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	3 Apr 2007 14:42:52 -0000
@@ -35,22 +35,17 @@
 define('CACHE_AGGRESSIVE', 2);
 
 /**
- * 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);
-
-/**
- * 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);
-
-/**
- * Indicates an error-level watchdog event; could be indicative of an attempt
- * to compromise the security of the site, or a serious system error.
+ *
+ * Error levels, as defined in RFC 3164 http://www.faqs.org/rfcs/rfc3164.html
  */
-define('WATCHDOG_ERROR', 2);
+define('WATCHDOG_EMERG',    0); // Emergency: system is unusable
+define('WATCHDOG_ALERT',    1); // Alert: action must be taken immediately
+define('WATCHDOG_CRITICAL', 2); // Critical: critical conditions
+define('WATCHDOG_ERROR',    3); // Error: error conditions
+define('WATCHDOG_WARNING',  4); // Warning: warning conditions
+define('WATCHDOG_NOTICE',   5); // Notice: normal but significant condition
+define('WATCHDOG_INFO',     6); // Informational: informational messages
+define('WATCHDOG_DEBUG',    7); // Debug: debug-level messages
 
 /**
  * First bootstrap phase: initialize configuration.
@@ -650,24 +645,34 @@ 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) {
+    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	3 Apr 2007 14:42:52 -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	3 Apr 2007 14:42:54 -0000
@@ -638,16 +638,6 @@ 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);
 }
 
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	3 Apr 2007 14:42:57 -0000
@@ -603,21 +603,6 @@ function system_install() {
         PRIMARY KEY (vid, type)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 
-      db_query("CREATE TABLE {watchdog} (
-        wid int NOT NULL auto_increment,
-        uid int NOT NULL default '0',
-        type varchar(16) NOT NULL default '',
-        message longtext NOT NULL,
-        severity tinyint unsigned NOT NULL default '0',
-        link varchar(255) NOT NULL default '',
-        location text NOT NULL,
-        referer varchar(128) NOT NULL default '',
-        hostname varchar(128) NOT NULL default '',
-        timestamp int NOT NULL default '0',
-        PRIMARY KEY (wid),
-        KEY (type)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-
       break;
     case 'pgsql':
       /* create unsigned types */
@@ -1089,20 +1074,6 @@ function system_install() {
         PRIMARY KEY (vid, type)
       )");
 
-      db_query("CREATE TABLE {watchdog} (
-        wid serial,
-        uid int NOT NULL default '0',
-        type varchar(16) NOT NULL default '',
-        message text NOT NULL,
-        severity smallint_unsigned NOT NULL default '0',
-        link varchar(255) NOT NULL default '',
-        location text NOT NULL default '',
-        referer varchar(128) NOT NULL default '',
-        hostname varchar(128) NOT NULL default '',
-        timestamp int NOT NULL default '0',
-        PRIMARY KEY (wid)
-      )");
-      db_query("CREATE INDEX {watchdog}_type_idx ON {watchdog} (type)");
       break;
   }
 
@@ -3724,6 +3695,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	3 Apr 2007 14:42:57 -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 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	3 Apr 2007 14:42:58 -0000
@@ -31,6 +31,14 @@ function watchdog_help($section) {
  * Implementation of hook_menu().
  */
 function watchdog_menu() {
+  $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,
+  );
+
   $items['admin/logs/watchdog'] = array(
     'title' => t('Recent log entries'),
     'description' => t('View events that have recently been logged.'),
@@ -65,6 +73,20 @@ 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().
  *
@@ -259,3 +281,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);
+  }
+}
