--- /tmp/civicrm_error/civicrm_error.module	2007-07-24 10:03:20.000000000 +1200
+++ civicrm_error.module	2008-10-22 22:18:23.000000000 +1300
@@ -16,46 +16,54 @@
 
   // civicrm error details
   if ($civicrm_error) {
-    $output .= "\n\n***CIVICRM ERROR***\n";
+    $output .= "\n\n============================ CIVICRM ERROR ============================\n";
     $output .= _civicrm_error_parse_array($civicrm_error);
   }
 
   // php error details
   if (function_exists('error_get_last')) {
-    $output .= "\n\n***PHP ERROR***\n";
+    $output .= "\n\n============================== PHP ERROR ==============================\n";
     $output .= _civicrm_error_parse_array(error_get_last());
   }
   elseif ($php_errormsg) {
-    $output .= "\n\n***PHP ERROR***\n";
+    $output .= "\n\n============================== PHP ERROR ==============================\n";
     $output .= _civicrm_error_parse_array($php_errormsg);
   }
 
   // user info
   global $user;
-  $output .= "\n\n***USER***\n";
+  $output .= "\n\n================================ USER =================================\n";
   $output .= _civicrm_error_parse_array($user);
 
   // $_SERVER
-  $output .= "\n\n***SERVER***\n";
+  $output .= "\n\n================================ SERVER ===============================\n";
   $output .= _civicrm_error_parse_array($_SERVER);
 
   // $_REQUEST
-  $output .= "\n\n***REQUEST***\n";
+  $output .= "\n\n=============================== REQUEST ===============================\n";
   $output .= _civicrm_error_parse_array($_REQUEST);
 
   // backtrace
   $backtrace = debug_backtrace();
-  $output .= "\n\n***BACKTRACE***\n";
+  $output .= "\n\n============================== BACKTRACE ==============================\n";
   foreach ($backtrace as $call) {
-    $output .= "**next call**\n";
+    $output .= "\n ------------------------------- Next Call -----------------------------\n\n";
     $output .= _civicrm_error_parse_array($call);
   }
 
-  // send email
+  // log the error
   $subject = 'CiviCRM error at '. $site;
   $to = variable_get('civicrm_error_to', variable_get("site_mail", ini_get("sendmail_from")));
-  drupal_mail('civicrm_error', $to, $subject, $output);
-
+  $errors_via = variable_get('civicrm_error_via', 'both') ;
+  switch( $errors_via ) {
+  case "watchdog":  
+    watchdog('civicrm error', '<pre>' . $output . '</pre>' ) ;
+    break ;
+  case "both":
+    watchdog('civicrm error', '<pre>' . $output . '</pre>' ) ;  
+  case "email":
+    drupal_mail('civicrm_error', $to, $subject, $output);
+  }
 }
 
 /**
@@ -67,7 +75,7 @@
       $value = print_r($value, true);
     }
     $key = str_pad($key .':', 20, ' ');
-    $output .= $key . (string)_civicrm_error_check_length($value) ." \n";
+    $output .= "\n" . $key . (string)_civicrm_error_check_length($value) ;
   }
   return $output ."\n";
 }
@@ -115,5 +123,14 @@
     '#description' => t("Select an email address to send all CiviCRM errors to."),
     '#required' => TRUE,
   );
+  $form['civicrm_error_via'] = array(
+    '#type' => 'select',
+    '#title' => t('Errors via'),
+    '#options' => array( 'both' => 'Email and Watchdog', 
+                         'watchdog' => 'Watchdog only', 
+                         'email' => 'Email only' ),
+    '#default_value' => variable_get('civicrm_error_via', 'both'),
+    '#description' => t("Method for error delivery."),
+  );
   return system_settings_form($form);
 }
