diff --git a/composer.json b/composer.json index c68cb4c..d061100 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "ext-json": "*", "adbario/php-dot-notation": "^3.1", "doctrine/inflector": "^2.0", + "filp/whoops": "^2.14", "laminas/laminas-diactoros": "^2.2", "laminas/laminas-httphandlerrunner": "^2.0", "monolog/monolog": "^2.0" diff --git a/composer.lock b/composer.lock index 0b9e4de..7a3681e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2e7b62620feaa98d7b4024a22f4b3320", + "content-hash": "c1e937afee36426ee92119997992bc91", "packages": [ { "name": "adbario/php-dot-notation", @@ -151,6 +151,77 @@ ], "time": "2021-10-22T20:16:43+00:00" }, + { + "name": "filp/whoops", + "version": "2.14.5", + "source": { + "type": "git", + "url": "https://github.com/filp/whoops.git", + "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/filp/whoops/zipball/a63e5e8f26ebbebf8ed3c5c691637325512eb0dc", + "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc", + "shasum": "" + }, + "require": { + "php": "^5.5.9 || ^7.0 || ^8.0", + "psr/log": "^1.0.1 || ^2.0 || ^3.0" + }, + "require-dev": { + "mockery/mockery": "^0.9 || ^1.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3", + "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0" + }, + "suggest": { + "symfony/var-dumper": "Pretty print complex values better with var-dumper available", + "whoops/soap": "Formats errors as SOAP responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Whoops\\": "src/Whoops/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Filipe Dobreira", + "homepage": "https://github.com/filp", + "role": "Developer" + } + ], + "description": "php error handling for cool kids", + "homepage": "https://filp.github.io/whoops/", + "keywords": [ + "error", + "exception", + "handling", + "library", + "throwable", + "whoops" + ], + "support": { + "issues": "https://github.com/filp/whoops/issues", + "source": "https://github.com/filp/whoops/tree/2.14.5" + }, + "funding": [ + { + "url": "https://github.com/denis-sokolov", + "type": "github" + } + ], + "time": "2022-01-07T12:00:00+00:00" + }, { "name": "laminas/laminas-diactoros", "version": "2.14.0", diff --git a/src/Log.php b/src/Log.php index 8aea1f2..be6bf29 100644 --- a/src/Log.php +++ b/src/Log.php @@ -379,25 +379,12 @@ public static function e(string $sMessage, array $aContext = array()): bool { * @return boolean Whether the record has been processed */ public static function ex(string $sMessage, Throwable $oThrowable, array $aContext = array()): bool { - $iTruncate = self::$iStackLimit; - $aStack = $oThrowable->getTrace(); - $iStack = count($aStack); - - if ($iStack > $iTruncate) { - $iRemaining = $iStack - $iTruncate; - $aStack = array_slice($aStack, 0, 5); - $aStack[] = [ - "__TRUNCATED__" => "$iRemaining entries cut from $iStack stack entries for brevity" - ]; - } - - $aStackCopy = []; - foreach($aStack as $aItem) { // Do NOT use a reference here as getTrace returns references to the actual args in the call stack which can then modify the real vars in the stack - if (isset($aItem['args'])) { - $aItem['args'] = self::replaceObjects($aItem['args']); - } - $aStackCopy[] = $aItem; - } + $oWhoops = new \Whoops\Run; + $oWhoops->allowQuit(false); + $oWhoops->writeToOutput(false); + $oWhoopsHandler = new \Whoops\Handler\JsonResponseHandler(); + $oWhoopsHandler->addTraceToOutput(true); + $oWhoops->pushHandler($oWhoopsHandler); $aContext['--exception'] = [ 'type' => get_class($oThrowable), @@ -405,7 +392,7 @@ public static function ex(string $sMessage, Throwable $oThrowable, array $aConte 'message' => $oThrowable->getMessage(), 'file' => $oThrowable->getFile(), 'line' => $oThrowable->getLine(), - 'stack' => json_encode($aStackCopy) + 'stack' => $oWhoops->handleException($oThrowable) ]; $aContext['--span'] = [