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 /core/ExceptionHandler.php | |
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 'core/ExceptionHandler.php')
-rw-r--r-- | core/ExceptionHandler.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 6c01785b95..c1f959ce6d 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -9,10 +9,13 @@ namespace Piwik; use Exception; +use Interop\Container\Exception\ContainerException; use Piwik\API\Request; use Piwik\API\ResponseBuilder; use Piwik\Container\ContainerDoesNotExistException; +use Piwik\Container\StaticContainer; use Piwik\Plugins\CoreAdminHome\CustomLogo; +use Psr\Log\LoggerInterface; /** * Contains Piwik's uncaught exception handler. @@ -41,6 +44,8 @@ class ExceptionHandler */ public static function dieWithCliError($exception) { + self::logException($exception); + $message = $exception->getMessage(); if (!method_exists($exception, 'isHtmlMessage') || !$exception->isHtmlMessage()) { @@ -65,6 +70,8 @@ class ExceptionHandler */ public static function dieWithHtmlErrorPage($exception) { + self::logException($exception); + Common::sendHeader('Content-Type: text/html; charset=utf-8'); try { @@ -137,4 +144,18 @@ class ExceptionHandler return $result; } + + private static function logException($exception) + { + try { + StaticContainer::get(LoggerInterface::class)->error('Uncaught exception: {exception}', [ + 'exception' => $exception, + 'ignoreInScreenWriter' => true, + ]); + } catch (ContainerException $ex) { + // ignore (occurs if exception is thrown when resolving DI entries) + } catch (ContainerDoesNotExistException $ex) { + // ignore + } + } } |