exception: Do not log PHP errors with severity DEBUG or INFO
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 24 Aug 2018 20:13:57 +0000 (21:13 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 6 Sep 2018 02:42:09 +0000 (03:42 +0100)
All PHP errors should be considered by monitoring queries
and error-rate alerts.

Levels DEBUG and INFO are for manual entries that can help in
debugging to see what path a program went down or what the
circumstances were in that code.

There is no reason to spread PHP error-types out on the full range
of PSR-3's DEBUG to ERROR spectrum. Instead, keep it within either
WARNING or ERROR, not below it.

Change-Id: I3f35a519b50aef5b93b9ab7a89a7c3e11d70681f

includes/exception/MWExceptionHandler.php

index 00dca9d..bd823b5 100644 (file)
@@ -176,8 +176,21 @@ class MWExceptionHandler {
                        return self::handleFatalError( ...func_get_args() );
                }
 
-               // Map error constant to error name (reverse-engineer PHP error
-               // reporting)
+               // Map PHP error constant to a PSR-3 severity level.
+               // Avoid use of "DEBUG" or "INFO" levels, unless the
+               // error should evade error monitoring and alerts.
+               //
+               // To decide the log level, ask yourself: "Has the
+               // program's behaviour diverged from what the written
+               // code expected?"
+               //
+               // For example, use of a deprecated method or violating a strict standard
+               // has no impact on functional behaviour (Warning). On the other hand,
+               // accessing an undefined variable makes behaviour diverge from what the
+               // author intended/expected. PHP recovers from an undefined variables by
+               // yielding null and continuing execution, but it remains a change in
+               // behaviour given the null was not part of the code and is likely not
+               // accounted for.
                switch ( $level ) {
                        case E_RECOVERABLE_ERROR:
                                $levelName = 'Error';
@@ -186,23 +199,27 @@ class MWExceptionHandler {
                        case E_WARNING:
                        case E_CORE_WARNING:
                        case E_COMPILE_WARNING:
-                       case E_USER_WARNING:
                                $levelName = 'Warning';
-                               $severity = LogLevel::WARNING;
+                               $severity = LogLevel::ERROR;
                                break;
                        case E_NOTICE:
-                       case E_USER_NOTICE:
                                $levelName = 'Notice';
-                               $severity = LogLevel::INFO;
+                               $severity = LogLevel::ERROR;
+                               break;
+                       case E_USER_WARNING:
+                       case E_USER_NOTICE:
+                               // Used by wfWarn(), MWDebug::warning()
+                               $levelName = 'Warning';
+                               $severity = LogLevel::WARNING;
                                break;
                        case E_STRICT:
                                $levelName = 'Strict Standards';
-                               $severity = LogLevel::DEBUG;
+                               $severity = LogLevel::WARNING;
                                break;
                        case E_DEPRECATED:
                        case E_USER_DEPRECATED:
                                $levelName = 'Deprecated';
-                               $severity = LogLevel::INFO;
+                               $severity = LogLevel::WARNING;
                                break;
                        default:
                                $levelName = 'Unknown error';