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	2 Apr 2007 05:24:56 -0000
@@ -659,15 +659,24 @@ function request_uri() {
 function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
   global $user, $base_root;
 
-  $current_db = db_set_active();
-
-  // Note: log the exact, entire absolute URL.
-  $request_uri = $base_root . request_uri();
-
-  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());
-
-  if ($current_db) {
-    db_set_active($current_db);
+  // Prepare the fields to be logged
+  $log_message = array(
+    'type'        => $type,
+    'message'     => $message,
+    'severity'    => $severity,
+    'link'        => $link,
+    'user'        => $user,
+    'request_uri' => $base_root . request_uri(),
+    'referer'     => referer_uri(),
+    'ip'          => $_SERVER['REMOTE_ADDR'],
+    'timestamp'   => time(),
+    );
+
+  // Call the logging hooks to log/process the message
+  foreach (module_implements('watchdog', TRUE) as $module) {
+    if (variable_get('watchdog_' . $module, 0)) {
+      module_invoke($module, 'watchdog', $log_message);
+    }
   }
 }
 
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.98
diff -u -F^f -r1.98 module.inc
--- includes/module.inc	4 Feb 2007 21:20:50 -0000	1.98
+++ includes/module.inc	2 Apr 2007 05:24:56 -0000
@@ -423,5 +423,5 @@ function module_invoke_all() {
  * Array of modules required by core.
  */
 function drupal_required_modules() {
-  return array('block', 'filter', 'node', 'system', 'user', 'watchdog');
+  return array('block', 'filter', 'node', 'system', 'user');
 }
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	2 Apr 2007 05:24:58 -0000
@@ -218,6 +218,12 @@ function system_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('system_error_reporting_settings'),
   );
+  $items['admin/settings/logging-alerts'] = array(
+    'title' => t('Logging and Alerts'),
+    'description' => t('Enable logging and alerts of Drupal watchdog messages to various destinations.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('system_watchdog_settings'),
+  );
   $items['admin/settings/performance'] = array(
     'title' => t('Performance'),
     'description' => t('Enable or disable page caching for anonymous users, and enable or disable CSS preprocessor.'),
@@ -638,16 +644,25 @@ function system_error_reporting_settings
     '#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.')
   );
 
-  $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(
-    '#type' => 'select',
-    '#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.')
+  return system_settings_form($form);
+}
+
+function system_watchdog_settings() {
+  $form['watchdog'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Logging and alert modules.'),
+    '#description' => t('This is a list of modules that can be used to log Drupal messages to various destinations, as well as send alerts.'),
   );
 
+  foreach (module_implements('watchdog', TRUE) as $module) {
+    $var = 'watchdog_' . $module;
+    $form[$var] = array(
+      '#type' => 'checkbox',
+      '#title' => $module,
+      '#default_value' => variable_get($var, 0),
+    );
+  }
+
   return system_settings_form($form);
 }
 
Index: modules/watchdog/watchdog.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/watchdog/watchdog.info,v
retrieving revision 1.3
diff -u -F^f -r1.3 watchdog.info
--- modules/watchdog/watchdog.info	21 Nov 2006 20:55:36 -0000	1.3
+++ modules/watchdog/watchdog.info	2 Apr 2007 05:24:58 -0000
@@ -1,5 +1,5 @@
 ; $Id: watchdog.info,v 1.3 2006/11/21 20:55:36 dries Exp $
 name = Watchdog
-description = Logs and records system events.
-package = Core - required
+description = Logs and records system events to the Drupal database.
+package = Logging and alerts
 version = VERSION
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	2 Apr 2007 05:24:58 -0000
@@ -31,6 +31,17 @@ function watchdog_help($section) {
  * Implementation of hook_menu().
  */
 function watchdog_menu() {
+  if (variable_get('watchdog_watchdog', 0)) {
+    $items['admin/settings/watchdog'] = array(
+      'title' => t('Watchdog'),
+      'description' => t('Settings for logging to the Drupal watchdog database table.'),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('watchdog_admin_settings'),
+      'weight' => 10,
+      'type' => MENU_LOCAL_TASK,
+    );
+  }
+
   $items['admin/logs/watchdog'] = array(
     'title' => t('Recent log entries'),
     'description' => t('View events that have recently been logged.'),
@@ -65,22 +76,40 @@ function watchdog_init() {
   }
 }
 
+function watchdog_admin_settings() {
+  $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(
+    '#type' => 'select',
+    '#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.')
+  );
+
+  return system_settings_form($form);
+}
+
 /**
  * Implementation of hook_cron().
  *
  * 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_watchdog', 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') {
-    db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
+  if (variable_get('watchdog_watchdog', 0)) {
+    if ($op == 'delete') {
+      db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
+    }
   }
 }
 
@@ -259,3 +288,24 @@ function _watchdog_get_message_types() {
 
   return $types;
 }
+
+function watchdog_watchdog($log = array()) {
+  $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)",
+    $log['user']->uid,
+    $log['type'],
+    $log['message'],
+    $log['severity'],
+    $log['link'],
+    $log['request_uri'],
+    $log['referer'],
+    $log['ip'],
+    $log['timestamp']);
+
+  if ($current_db) {
+    db_set_active($current_db);
+  }
+}
