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
This commit is contained in:
Timo Tijhof 2018-08-24 21:13:57 +01:00
parent 1ded08465b
commit ef06b528d9

View 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:
$levelName = 'Warning';
$severity = LogLevel::ERROR;
break;
case E_NOTICE:
$levelName = 'Notice';
$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_NOTICE:
case E_USER_NOTICE:
$levelName = 'Notice';
$severity = LogLevel::INFO;
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';