Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.245
diff -u -r1.245 bootstrap.inc
--- includes/bootstrap.inc	2 Nov 2008 10:56:35 -0000	1.245
+++ includes/bootstrap.inc	3 Nov 2008 05:14:07 -0000
@@ -881,7 +881,7 @@
  * @see watchdog_severity_levels()
  */
 function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
-  global $user, $base_root;
+  global $user, $base_url, $base_root;
 
   static $in_error_state = FALSE;
 
@@ -904,9 +904,26 @@
       'timestamp'   => REQUEST_TIME,
     );
 
-    // Call the logging hooks to log/process the message
-    foreach (module_implements('watchdog', TRUE) as $module) {
-      module_invoke($module, 'watchdog', $log_message);
+    if (function_exists('module_implements')) {
+      // Call the logging hooks to log/process the message
+      foreach (module_implements('watchdog', TRUE) as $module) {
+        module_invoke($module, 'watchdog', $log_message);
+      }
+    }
+    else {
+      // This section is for handling errors that happen too early, before module.inc
+      // gets loaded. If that happens, we don't have module_implements() yet, and therefore
+      // Drupal will abort if we call it. So we log stuff to the web server's log.
+      $message  = $base_url;
+      $message .= '|type='    . $type;
+      $message .= '|ip='      . $log_message['ip'];
+      $message .= '|uri='     . $log_message['request_uri'];
+      $message .= '|referer=' . $log_message['referer'];
+      $message .= '|uid='     . $user->uid;
+      $message .= '|link='    . strip_tags($link);
+      $message .= '|' . strip_tags(is_null($variables) ? $message : strtr($message, $variables));
+
+      error_log($message);
     }
   }
   $in_error_state = FALSE;
