diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-02-18 17:02:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-18 17:02:29 +0300 |
commit | 8d3fe62389469347f7ebc551ee36f4527655b804 (patch) | |
tree | beea4c5ba26e3969e47441f948c152b471bf20a9 /plugins/Monolog/config | |
parent | 99d42f5b8ca81f5481635c0cbea794d4b7de783b (diff) |
Enable fingers crossed handler via INI config and show backtrace in logs/archive api output (#13923)
* Add config to use FringersCrossedHandler (untested)
* Get to work in different contexts.
* Add changelog note.
* Make sure more exceptions make it to the logs, make backtrace include previous exceptions, do not use screen writer if in cli mode, always print backtrace if in CLI mode and archivephp triggered.
* Add log capturing handler.
* Remove options from global.ini.php sibnce they may be temporary.
* Add UI test triggering an error w/ the screen handler.
* Add some more log statements, ignore logs in screen writer, replace part of message in ExceptionToTextProcessor instead of whole message.
* Add missing license.
* Update changelog, move new item to 3.9
* Fixing some integration tests.
* Fix another unit test.
* One more test fix.
* Try to get rid of xss testing warning.
* Try again to get rid of warning.
* Try again to get rid of warning.
* Try again to get rid of warning.
Diffstat (limited to 'plugins/Monolog/config')
-rw-r--r-- | plugins/Monolog/config/config.php | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php index 19e7752479..b9e9e0c62f 100644 --- a/plugins/Monolog/config/config.php +++ b/plugins/Monolog/config/config.php @@ -4,6 +4,7 @@ use Interop\Container\ContainerInterface; use Monolog\Logger; use Piwik\Log; use Piwik\Plugins\Monolog\Handler\FileHandler; +use Piwik\Plugins\Monolog\Handler\LogCaptureHandler; return array( @@ -17,7 +18,7 @@ return array( 'screen' => 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler', 'database' => 'Piwik\Plugins\Monolog\Handler\DatabaseHandler', ), - 'log.handlers' => DI\factory(function (ContainerInterface $c) { + 'log.handlers' => DI\factory(function (\DI\Container $c) { if ($c->has('ini.log.log_writers')) { $writerNames = $c->get('ini.log.log_writers'); } else { @@ -26,13 +27,50 @@ return array( $classes = $c->get('log.handler.classes'); + $logConfig = $c->get(\Piwik\Config::class)->log; + $enableFingersCrossed = isset($logConfig['enable_fingers_crossed_handler']) && $logConfig['enable_fingers_crossed_handler'] == 1; + $fingersCrossedStopBuffering = isset($logConfig['fingers_crossed_stop_buffering_on_activation']) && $logConfig['fingers_crossed_stop_buffering_on_activation'] == 1; + $enableLogCaptureHandler = isset($logConfig['enable_log_capture_handler']) && $logConfig['enable_log_capture_handler'] == 1; + + $isLogBufferingAllowed = !\Piwik\Common::isPhpCliMode() + || \Piwik\SettingsServer::isArchivePhpTriggered() + || \Piwik\CliMulti::isCliMultiRequest(); + $writerNames = array_map('trim', $writerNames); $writers = array(); foreach ($writerNames as $writerName) { + if ($writerName === 'screen' && \Piwik\Common::isPhpCliMode()) { + continue; // screen writer is only valid for web requests + } + if (isset($classes[$writerName])) { - $writers[$writerName] = $c->get($classes[$writerName]); + // wrap the handler in FingersCrossedHandler if we can and this isn't the screen handler + + /** @var \Monolog\Handler\HandlerInterface $handler */ + $handler = $c->make($classes[$writerName]); + if ($enableFingersCrossed + && $writerName !== 'screen' + && $handler instanceof \Monolog\Handler\AbstractHandler + && $isLogBufferingAllowed + ) { + $passthruLevel = $handler->getLevel(); + + $handler->setLevel(Logger::DEBUG); + + $handler = new \Monolog\Handler\FingersCrossedHandler($handler, $activationStrategy = null, $bufferSize = 0, + $bubble = true, $fingersCrossedStopBuffering, $passthruLevel); + } + + $writers[$writerName] = $handler; } } + + if ($enableLogCaptureHandler + && $isLogBufferingAllowed + ) { + $writers[] = $c->get(LogCaptureHandler::class); + } + return array_values($writers); }), |