diff --git a/core/includes/common.inc b/core/includes/common.inc
index 037c5b0..e1d46b1 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -1182,7 +1182,12 @@ function debug($data, $label = NULL, $print_r = TRUE) {
   // Display values with pre-formatting to increase readability.
   $string = '<pre>' . $string . '</pre>';
 
+  // Before triggering the error, tell _drupal_log_error() that this is a debug
+  // message.
+  $debug_active = &drupal_static(__FUNCTION__, FALSE);
+  $debug_active = TRUE;
   trigger_error(trim($label ? "$label: $string" : $string));
+  $debug_active = FALSE;
 }
 
 /**
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index e3ad1c8..5bd9c31 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -207,10 +207,9 @@ function _drupal_log_error($error, $fatal = FALSE) {
     if (error_displayable($error)) {
       $class = 'error';
 
-      // If error type is 'User notice' then treat it as debug information
+      // If the error was triggered by debug(), treat it as debug information
       // instead of an error message.
-      // @see debug()
-      if ($error['%type'] == 'User notice') {
+      if (drupal_static('debug')) {
         $error['%type'] = 'Debug';
         $class = 'status';
       }
