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 16:26:18 -0000
@@ -35,22 +35,39 @@
 define('CACHE_AGGRESSIVE', 2);
 
 /**
+ * Indicates a debug-level watchdog event; used only by developers.
+ */
+define('WATCHDOG_DEBUG', 0);
+
+/**
+ * Indicates an information-level watchdog event; these are normally the lowest
+ * level.
+ */
+define('WATCHDOG_INFO', 1);
+
+/**
  * Indicates a notice-level watchdog event; these are normally notifications
  * of normal system events that have occurred and can usually be safely ignored.
  */
-define('WATCHDOG_NOTICE', 0);
+define('WATCHDOG_NOTICE', 2);
 
 /**
  * Indicates a warning-level watchdog event; this can be triggered by an error
  * in a module that does not impact the overall functionality of the site.
  */
-define('WATCHDOG_WARNING', 1);
+define('WATCHDOG_WARNING', 3);
 
 /**
  * Indicates an error-level watchdog event; could be indicative of an attempt
  * to compromise the security of the site, or a serious system error.
  */
-define('WATCHDOG_ERROR', 2);
+define('WATCHDOG_ERROR', 4);
+
+/**
+ * Indicates an error-level watchdog event; could be indicative of an attempt
+ * to compromise the security of the site, or a serious system error.
+ */
+define('WATCHDOG_CRITICAL', 5);
 
 /**
  * First bootstrap phase: initialize configuration.
@@ -650,24 +667,36 @@ function request_uri() {
  *   The message to store in the log.
  * @param $severity
  *   The severity of the message. One of the following values:
+ *   - WATCHDOG_DEBUG
+ *   - WATCHDOG_INFO
  *   - WATCHDOG_NOTICE
  *   - WATCHDOG_WARNING
  *   - WATCHDOG_ERROR
+ *   - WATCHDOG_CRITICTAL
  * @param $link
  *   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();
-
-  // 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 16:26:18 -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 16:26:20 -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) {
+    $module_variable = 'watchdog_' . $module;
+    $form[$module_variable] = array(
+      '#type' => 'checkbox',
+      '#title' => $module,
+      '#default_value' => variable_get($module_variable, 0),
+    );
+  }
+
   return system_settings_form($form);
 }
 
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.88
diff -u -F^f -r1.88 system.install
--- modules/system/system.install	30 Mar 2007 08:47:58 -0000	1.88
+++ modules/system/system.install	2 Apr 2007 16:26:23 -0000
@@ -3724,6 +3724,17 @@ function system_update_2006() {
 }
 
 /**
+ * Change the severity column in the watchdog table to the new values.
+ */
+function system_update_2007() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE {watchdog} SET severity = %d WHERE severity = 0", WATCHDOG_NOTICE);
+  $ret[] = update_sql("UPDATE {watchdog} SET severity = %d WHERE severity = 1", WATCHDOG_WARNING);
+  $ret[] = update_sql("UPDATE {watchdog} SET severity = %d WHERE severity = 2", WATCHDOG_ERROR);
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-5.0-to-x.x"
  * The next series of updates should start at 3000.
  */
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 16:26:23 -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 16:26:24 -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);
+  }
+}
