diff --git a/docs/03-a-deeper-look-at-wonolog.md b/docs/03-a-deeper-look-at-wonolog.md index e644ae3..5c4fd44 100644 --- a/docs/03-a-deeper-look-at-wonolog.md +++ b/docs/03-a-deeper-look-at-wonolog.md @@ -47,7 +47,7 @@ Please keep in mind that such customization **must be done in an MU plugin**, be ## Wonolog PHP Error Handler -As mentioned before, by default, Wonolog logs all kinds of PHP errors. +As mentioned before, by default, Wonolog logs all kinds of PHP errors. It does not log silenced PHP errors. This is possible because Wonolog registers custom error and exception handlers. @@ -76,6 +76,10 @@ The **log channel** used for these events is `Channels::PHP_ERROR`, and the **lo Refer to [Wonolog Customization](05-wonolog-customization.md) to learn how to customize or even disable this PHP error handler. +If you want to log also silenced PHP errors you can do so with a filter: +``` +add_filter('wonolog.report-silenced-errors', '__return_true'); +``` ## Default Handler Minimum Log Level diff --git a/src/PhpErrorController.php b/src/PhpErrorController.php index 2e93104..66a5ec7 100644 --- a/src/PhpErrorController.php +++ b/src/PhpErrorController.php @@ -67,6 +67,23 @@ class PhpErrorController { */ public function on_error( $num, $str, $file, $line, $context = NULL ) { + $level = isset( self::$errors_level_map[ $num ] ) + ? self::$errors_level_map[ $num ] + : NULL; + + $report_silenced = apply_filters( + 'wonolog.report-silenced-errors', + error_reporting() !== 0, + $num, + $str, + $file, + $line + ); + + if ( $level === NULL || ! $report_silenced ) { + return FALSE; + } + $log_context = []; if ( $context ) { $skip_keys = array_merge( array_keys( $GLOBALS ), self::$super_globals_keys ); @@ -80,7 +97,7 @@ public function on_error( $num, $str, $file, $line, $context = NULL ) { // Log the PHP error. do_action( \Inpsyde\Wonolog\LOG, - new Log( $str, self::$errors_level_map[ $num ], Channels::PHP_ERROR, $log_context ) + new Log( $str, $level, Channels::PHP_ERROR, $log_context ) ); return FALSE;