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';
       }
diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
index 4737e80..18e7967 100644
--- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
@@ -73,10 +73,9 @@ protected function onHtml(GetResponseForExceptionEvent $event) {
     // of message to be displayed, and unconditionally in update.php.
     $message = '';
     if (error_displayable($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';
       }
 
diff --git a/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php b/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
index 6683580..578a3f9 100644
--- a/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
+++ b/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
@@ -60,7 +60,7 @@ protected function setUp() {
    * Override the error method so we can test for the expected exception.
    */
   protected function error($message = '', $group = 'Other', array $caller = NULL) {
-    if ($group == 'User notice') {
+    if ($group == 'Debug' || ($group == 'User notice' && drupal_static('debug'))) {
       // Since 'User notice' is set by trigger_error() which is used for debug
       // set the message to a status of 'debug'.
       return $this->assert('debug', $message, 'Debug', $caller);
diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php
index 14d7909..a22a45c 100644
--- a/core/modules/simpletest/src/TestBase.php
+++ b/core/modules/simpletest/src/TestBase.php
@@ -807,7 +807,7 @@ protected function fail($message = NULL, $group = 'Other') {
    *   FALSE.
    */
   protected function error($message = '', $group = 'Other', array $caller = NULL) {
-    if ($group == 'User notice') {
+    if ($group == 'Debug' || ($group == 'User notice' && drupal_static('debug'))) {
       // Since 'User notice' is set by trigger_error() which is used for debug
       // set the message to a status of 'debug'.
       return $this->assert('debug', $message, 'Debug', $caller);
@@ -841,7 +841,7 @@ protected function verbose($message) {
       // to avoid invoking the theme system, so that unit tests
       // can use verbose() as well.
       $url = '<a href="' . $url . '" target="_blank">Verbose message</a>';
-      $this->error($url, 'User notice');
+      $this->error($url, 'Debug');
     }
     $this->verboseId++;
   }
diff --git a/core/modules/system/src/Tests/Common/SimpleTestErrorCollectorTest.php b/core/modules/system/src/Tests/Common/SimpleTestErrorCollectorTest.php
index 1be7e94..375ad3c 100644
--- a/core/modules/system/src/Tests/Common/SimpleTestErrorCollectorTest.php
+++ b/core/modules/system/src/Tests/Common/SimpleTestErrorCollectorTest.php
@@ -63,10 +63,10 @@ protected function error($message = '', $group = 'Other', array $caller = NULL)
     // Due to a WTF elsewhere, simpletest treats debug() and verbose()
     // messages as if they were an 'error'. But, we don't want to collect
     // those here. This function just wants to collect the real errors (PHP
-    // notices, PHP fatal errors, etc.), and let all the 'errors' from the
-    // 'User notice' group bubble up to the parent classes to be handled (and
+    // notices, PHP fatal errors, etc.), and let all the 'errors' from debug()
+    // and verbose() bubble up to the parent classes to be handled (and
     // eventually displayed) as normal.
-    if ($group == 'User notice') {
+    if ($group == 'Debug' || ($group == 'User notice' && drupal_static('debug'))) {
       parent::error($message, $group, $caller);
     }
     // Everything else should be collected but not propagated.
