Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.152
diff -u -F^f -r1.152 bootstrap.inc
--- includes/bootstrap.inc	4 Apr 2007 20:50:53 -0000	1.152
+++ includes/bootstrap.inc	6 Apr 2007 02:59:29 -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.
+ *
+ * Severity 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.
@@ -649,25 +644,29 @@ function request_uri() {
  * @param $message
  *   The message to store in the log.
  * @param $severity
- *   The severity of the message. One of the following values:
- *   - WATCHDOG_NOTICE
- *   - WATCHDOG_WARNING
- *   - WATCHDOG_ERROR
+ *   The severity of the message, as per RFC 3164
  * @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	6 Apr 2007 02:59:29 -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	6 Apr 2007 02:59:31 -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	6 Apr 2007 02:59:34 -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	6 Apr 2007 02:59:34 -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	6 Apr 2007 02:59:34 -0000
@@ -31,6 +31,13 @@ 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'),
+  );
+
   $items['admin/logs/watchdog'] = array(
     'title' => t('Recent log entries'),
     'description' => t('View events that have recently been logged.'),
@@ -65,6 +72,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().
  *
@@ -109,6 +130,7 @@ function watchdog_form_overview() {
  * Menu callback; displays a listing of log messages.
  */
 function watchdog_overview() {
+  $rows = array();
   $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')));
@@ -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);
+  }
+}
Index: modules/watchdog/watchdog.install
===================================================================
RCS file: modules/watchdog/watchdog.install
diff -N modules/watchdog/watchdog.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/watchdog/watchdog.install	6 Apr 2007 02:59:34 -0000
@@ -0,0 +1,53 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function watchdog_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      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':
+      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;
+  }
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function watchdog_uninstall() {
+  db_query('DROP TABLE {watchdog}');
+}
Index: profiles/default/default.profile
===================================================================
RCS file: /cvs/drupal/drupal/profiles/default/default.profile,v
retrieving revision 1.8
diff -u -F^f -r1.8 default.profile
--- profiles/default/default.profile	27 Mar 2007 05:13:54 -0000	1.8
+++ profiles/default/default.profile	6 Apr 2007 02:59:35 -0000
@@ -8,7 +8,7 @@
  *  An array of modules to be enabled.
  */
 function default_profile_modules() {
-  return array('color', 'comment', 'help', 'taxonomy');
+  return array('color', 'comment', 'help', 'taxonomy', 'watchdog');
 }
 
 /**
Index: sites/all/modules/logging_alerts/emaillog/emaillog.info
===================================================================
RCS file: sites/all/modules/logging_alerts/emaillog/emaillog.info
diff -N sites/all/modules/logging_alerts/emaillog/emaillog.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sites/all/modules/logging_alerts/emaillog/emaillog.info	6 Apr 2007 02:59:36 -0000
@@ -0,0 +1,5 @@
+; $Id$
+name = Email logging and alerts
+description = Sends logs and alerts to email addresses, with different severity going to different emails.
+package = Logging and alerts
+version = VERSION
Index: sites/all/modules/logging_alerts/emaillog/emaillog.module
===================================================================
RCS file: sites/all/modules/logging_alerts/emaillog/emaillog.module
diff -N sites/all/modules/logging_alerts/emaillog/emaillog.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sites/all/modules/logging_alerts/emaillog/emaillog.module	6 Apr 2007 02:59:36 -0000
@@ -0,0 +1,98 @@
+<?php
+// $Id$
+
+// Copyright 2007 Khalid Baheyeldin http://2bits.com
+
+/**
+ * @file
+ * Sends logs and alerts to email addresses.
+ */
+
+/**
+ * Implementation of hook_help().
+ */
+function emaillog_help($section) {
+  switch ($section) {
+    case 'admin/help#emaillog':
+      return '<p>'. t('Sends logs and alerts to email addresses, with different severity going to different emails.') .'</p>';
+  }
+}
+
+function emaillog_menu() {
+  $items['admin/settings/emaillog'] = array(
+    'title' => t('Email logging and alerts'),
+    'description' => t('Settings for logging and alerts to email addresses.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('emaillog_admin_settings'),
+  );
+  return $items;
+}
+
+function emaillog_admin_settings() {
+  foreach(emaillog_severity_list() as $severity => $description) {
+    $key = 'emaillog_' . $severity;
+    $form[$key] = array(
+      '#type' => 'textfield',
+      '#title' => t('Email address for severity @description', array('@description' => $description)),
+      '#default_value' => variable_get($key, variable_get('site_mail', ini_get('sendmail_from'))),
+      '#description' => t('The email address to send log entries of severity @description to.', array('@description' => $description)),
+    );
+  }
+
+  return system_settings_form($form);
+}
+
+function emaillog_severity_list() {
+  return array(
+    WATCHDOG_EMERG    => t('Emergency'),
+    WATCHDOG_ALERT    => t('Alert'),
+    WATCHDOG_CRITICAL => t('Critical'),
+    WATCHDOG_ERROR    => t('Error'),
+    WATCHDOG_WARNING  => t('Warning'),
+    WATCHDOG_NOTICE   => t('Notice'),
+    WATCHDOG_INFO     => t('Info'),
+    WATCHDOG_DEBUG    => t('Debug'),
+  );
+}
+
+function emaillog_watchdog($log) {
+  $severity_list = emaillog_severity_list();
+  $to = variable_get('emaillog_' . $log['severity'], variable_get('site_mail', ini_get('sendmail_from')));
+  $subject = t('[@site_name] @severity_desc: Alert from your web site', array(
+    '@site_name' => variable_get('site_name', 'Drupal'),
+    '@severity_desc' => $severity_list[$log['severity']]));
+  drupal_mail('emaillog', $to, $subject, theme('emaillog_message', $log), $from = NULL, $headers = array());
+}
+
+function theme_emaillog_message($log_msg = array()) {
+  global $base_url;
+
+  $severity_list = emaillog_severity_list();
+
+  $message  = "\nSite:         @base_url";
+  $message .= "\nSeverity:     (@severity) @severity_desc";
+  $message .= "\nTimestamp:    @timestamp";
+  $message .= "\nType:         @type";
+  $message .= "\nIP Address:   @ip";
+  $message .= "\nRequest URI:  @request_uri";
+  $message .= "\nReferrer URI: @referer_uri";
+  $message .= "\nUser:         (@uid) @name";
+  $message .= "\nLink:         @link";
+  $message .= "\nMessage:      \n\n@message";
+
+  $message = t($message, array(
+    '@base_url'      => $base_url,
+    '@severity'      => $log_msg['severity'],
+    '@severity_desc' => $severity_list[$log_msg['severity']],
+    '@timestamp'     => $log_msg['timestamp'],
+    '@type'          => $log_msg['type'],
+    '@ip'            => $log_msg['ip'],
+    '@request_uri'   => $log_msg['request_uri'],
+    '@referer_uri'   => $log_msg['referer'],
+    '@uid'           => $log_msg['user']->uid,
+    '@name'          => $log_msg['user']->name,
+    '@link'          => strip_tags($log_msg['link']),
+    '@message'       => strip_tags($log_msg['message']),
+  ));
+  return $message;
+}
Index: sites/all/modules/logging_alerts/syslog/syslog.info
===================================================================
RCS file: sites/all/modules/logging_alerts/syslog/syslog.info
diff -N sites/all/modules/logging_alerts/syslog/syslog.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sites/all/modules/logging_alerts/syslog/syslog.info	6 Apr 2007 02:59:36 -0000
@@ -0,0 +1,5 @@
+; $Id$
+name = Syslog
+description = Logs and records system events to syslog.
+package = Logging and alerts
+version = VERSION
Index: sites/all/modules/logging_alerts/syslog/syslog.module
===================================================================
RCS file: sites/all/modules/logging_alerts/syslog/syslog.module
diff -N sites/all/modules/logging_alerts/syslog/syslog.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sites/all/modules/logging_alerts/syslog/syslog.module	6 Apr 2007 02:59:36 -0000
@@ -0,0 +1,88 @@
+<?php
+// $Id$
+
+// Copyright 2007 Khalid Baheyeldin http://2bits.com
+
+/**
+ * @file
+ * Redirects logging messages to syslog.
+ */
+
+define('SYSLOG_FACILITY', 'syslog_facility');
+/**
+ * Implementation of hook_help().
+ */
+function syslog_help($section) {
+  switch ($section) {
+    case 'admin/help#syslog':
+      return '<p>'. t('Provides the facility to log Drupal messages to the operating systems\' syslog facility.') .'</p>';
+  }
+}
+
+function syslog_menu() {
+  $items['admin/settings/syslog'] = array(
+    'title' => t('Syslog'),
+    'description' => t('Settings for syslog logging.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('syslog_admin_settings'),
+  );
+  return $items;
+}
+
+function syslog_admin_settings() {
+  $form[SYSLOG_FACILITY] = array(
+    '#type'          => 'select',
+    '#title'         => t('Syslog facility to send to'),
+    '#default_value' => variable_get(SYSLOG_FACILITY, LOG_LOCAL0),
+    '#options'       => syslog_facility_list(),
+    '#description'   => t('Select the syslog facility to send Drupal\'s messages to. For more information on syslog facilities, See !syslog_conf and !php', array(
+      '!php'         => l("PHP's syslog", 'http://www.php.net/manual/en/function.openlog.php'),
+      '!syslog_conf' => l('UNIX/Linux syslog.conf', 'http://www.rt.com/man/syslog.5.html'),
+      )),
+  );
+
+  return system_settings_form($form);
+}
+
+function syslog_facility_list() {
+  return array(
+    LOG_USER   => t('LOG_USER - User level messages. Use this for Windows.'),
+    LOG_LOCAL0 => t('LOG_LOCAL0 - Local 0'),
+    LOG_LOCAL1 => t('LOG_LOCAL1 - Local 1'),
+    LOG_LOCAL2 => t('LOG_LOCAL2 - Local 2'),
+    LOG_LOCAL3 => t('LOG_LOCAL3 - Local 3'),
+    LOG_LOCAL4 => t('LOG_LOCAL4 - Local 4'),
+    LOG_LOCAL5 => t('LOG_LOCAL5 - Local 5'),
+    LOG_LOCAL6 => t('LOG_LOCAL6 - Local 6'),
+    LOG_LOCAL7 => t('LOG_LOCAL7 - Local 7'),
+  );
+}
+
+function syslog_watchdog($log) {
+  static $log_initialized = FALSE;
+
+  if (!$log_initialized) {
+    openlog('drupal', LOG_NDELAY, variable_get(SYSLOG_FACILITY, LOG_LOCAL0));
+    $log_initialized = TRUE;
+  }
+
+  syslog($log['severity'], theme('syslog_message', $log));
+}
+
+function theme_syslog_message($log_msg = array()) {
+  global $base_url;
+
+  $message = t('@base_url|@timestamp|@type|@uid|@ip|@request_uri|@referer_uri|@link|@message',
+    array(
+      '@base_url'    => $base_url,
+      '@timestamp'   => $log_msg['timestamp'],
+      '@type'        => $log_msg['type'],
+      '@ip'          => $log_msg['ip'],
+      '@request_uri' => $log_msg['request_uri'],
+      '@referer_uri' => $log_msg['referer'],
+      '@uid'         => $log_msg['user']->uid,
+      '@link'        => strip_tags($log_msg['link']),
+      '@message'     => strip_tags($log_msg['message']),
+    ));
+  return $message;
+}
