From ef06b528d9f34d118fe8b750eeb8aebc16da3ec8 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 24 Aug 2018 21:13:57 +0100 Subject: [PATCH] exception: Do not log PHP errors with severity DEBUG or INFO 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 | 33 +++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index 00dca9ddf6..bd823b5e07 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -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'; -- 2.20.1