Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.151
diff -u -F^F -r1.151 bootstrap.inc
--- includes/bootstrap.inc	28 Mar 2007 14:08:21 -0000	1.151
+++ includes/bootstrap.inc	28 Mar 2007 23:45:31 -0000
@@ -657,17 +657,35 @@
  *   A link to associate with the message.
  */
 function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
-  global $user, $base_root;
-
-  $current_db = db_set_active();
+  global $user, $base_root, $base_url;
 
   // Note: log the exact, entire absolute URL.
   $request_uri = $base_root . request_uri();
+  $ip = $_SERVER['REMOTE_ADDR'];
+
+  if (variable_get('watchdog_syslog', 0)) {
+    switch($severity) {
+      case WATCHDOG_ERROR:
+        $severity = LOG_ERR;
+        break;
+      case WATCHDOG_WARNING:
+        $severity = LOG_WARNING;
+        break;
+      case WATCHDOG_NOTICE:
+        $severity = LOG_NOTICE;
+        break;
+    }
+    $log_msg = t('Drupal|@base_url|@type|@uid|@ip|@request_uri|@referer_uri|@link|@message', array( '@base_url' => $base_url, '@type' => $type, '@ip' => $ip, '@request_uri' => $request_uri, '@referer_uri' => referer_uri(), '@uid' => $user->uid, '@link' => $link, '@message' => strip_tags($message)));
+    syslog($severity, $log_msg);
+  }
+  else {
+    $current_db = db_set_active();
 
-  db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, $request_uri, referer_uri(), $_SERVER['REMOTE_ADDR'], time());
+    db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, $request_uri, referer_uri(), $ip, time());
 
-  if ($current_db) {
-    db_set_active($current_db);
+    if ($current_db) {
+      db_set_active($current_db);
+    }
   }
 }
 
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.460
diff -u -F^F -r1.460 system.module
--- modules/system/system.module	27 Mar 2007 05:13:54 -0000	1.460
+++ modules/system/system.module	28 Mar 2007 23:45:33 -0000
@@ -638,6 +638,14 @@
     '#description' =>  t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.')
   );
 
+  $form['watchdog_syslog'] = array(
+    '#type' => 'radios',
+    '#title' => t('Log to syslog'),
+    '#default_value' => variable_get('watchdog_syslog', 0),
+    '#options' => array(t('Disabled'), t('Enabled')),
+    '#description' => t('This option causes Drupal to send watchdog messages to syslog instead of the watchdog table. This is available on UNIX like systems, and can decrease the load on the database. If you enable this option, the watchdog messages will not be visible from Drupal, but from your system syslog.'),
+  );
+
   $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
   $period['1000000000'] = t('Never');
   $form['watchdog_clear'] = array(
@@ -645,7 +653,7 @@
     '#title' => t('Discard log entries older than'),
     '#default_value' => variable_get('watchdog_clear', 604800),
     '#options' => $period,
-    '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.')
+    '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab. Does not have any effect when using syslog.')
   );
 
   return system_settings_form($form);
Index: modules/watchdog/watchdog.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/watchdog/watchdog.module,v
retrieving revision 1.171
diff -u -F^F -r1.171 watchdog.module
--- modules/watchdog/watchdog.module	27 Feb 2007 12:29:22 -0000	1.171
+++ modules/watchdog/watchdog.module	28 Mar 2007 23:45:33 -0000
@@ -71,15 +71,17 @@
  * Remove expired log messages and flood control events.
  */
 function watchdog_cron() {
-  db_query('DELETE FROM {watchdog} WHERE timestamp < %d', time() - variable_get('watchdog_clear', 604800));
-  db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
+  if (!variable_get('watchdog_syslog', 0)) {
+    db_query('DELETE FROM {watchdog} WHERE timestamp < %d', time() - variable_get('watchdog_clear', 604800));
+    db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
+  }
 }
 
 /**
  * Implementation of hook_user().
  */
 function watchdog_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
+  if ($op == 'delete' && !variable_get('watchdog_syslog', 0)) {
     db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
   }
 }
@@ -109,6 +111,10 @@
  * Menu callback; displays a listing of log messages.
  */
 function watchdog_overview() {
+  if (variable_get('watchdog_syslog', 1)) {
+    return t('Watchdog is set for syslog, and hence log entries cannot be displayed in Drupal. Use your systems syslog viewer instead.');
+  }
+
   $icons = array(WATCHDOG_NOTICE  => '',
                  WATCHDOG_WARNING => theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')),
                  WATCHDOG_ERROR   => theme('image', 'misc/watchdog-error.png', t('error'), t('error')));
@@ -252,6 +258,10 @@
 function _watchdog_get_message_types() {
   $types = array();
 
+  if (variable_get('watchdog_syslog', 1)) {
+    return $types;
+  }
+
   $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
   while ($object = db_fetch_object($result)) {
     $types[] = $object->type;
