Browse Source

5.x Make deprecation warnings log at debug

It is often useful to have info logging on in production. However, you
can't do that with the default CakePHP logging as we log deprecation
warnings at info. Moving deprecations to debug allows us to have easier
to control logging.
Mark Story 2 years ago
parent
commit
400bde03a8
2 changed files with 6 additions and 6 deletions
  1. 5 5
      src/Error/ErrorLogger.php
  2. 1 1
      tests/TestCase/Error/ErrorTrapTest.php

+ 5 - 5
src/Error/ErrorLogger.php

@@ -64,12 +64,12 @@ class ErrorLogger implements ErrorLoggerInterface
         if ($includeTrace) {
             $message .= "\nTrace:\n" . $error->getTraceAsString() . "\n";
         }
-        $logMap = [
+        $label = $error->getLabel();
+        $level = match ($label) {
             'strict' => LOG_NOTICE,
-            'deprecated' => LOG_NOTICE,
-        ];
-        $level = $error->getLabel();
-        $level = $logMap[$level] ?? $level;
+            'deprecated' => LOG_DEBUG,
+            default => $label,
+        };
 
         Log::write($level, $message);
     }

+ 1 - 1
tests/TestCase/Error/ErrorTrapTest.php

@@ -104,7 +104,7 @@ class ErrorTrapTest extends TestCase
             // PHP error level, expected log level
             [E_USER_WARNING, 'warning'],
             [E_USER_NOTICE, 'notice'],
-            [E_USER_DEPRECATED, 'notice'],
+            [E_USER_DEPRECATED, 'debug'],
         ];
     }