Skip to content

Commit b1f9aec

Browse files
committed
Using whoops to generate the stack for Log::ex
1 parent 45c2708 commit b1f9aec

File tree

3 files changed

+80
-21
lines changed

3 files changed

+80
-21
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"ext-json": "*",
2828
"adbario/php-dot-notation": "^3.1",
2929
"doctrine/inflector": "^2.0",
30+
"filp/whoops": "^2.14",
3031
"laminas/laminas-diactoros": "^2.2",
3132
"laminas/laminas-httphandlerrunner": "^2.0",
3233
"monolog/monolog": "^2.0"

composer.lock

+72-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Log.php

+7-20
Original file line numberDiff line numberDiff line change
@@ -379,33 +379,20 @@ public static function e(string $sMessage, array $aContext = array()): bool {
379379
* @return boolean Whether the record has been processed
380380
*/
381381
public static function ex(string $sMessage, Throwable $oThrowable, array $aContext = array()): bool {
382-
$iTruncate = self::$iStackLimit;
383-
$aStack = $oThrowable->getTrace();
384-
$iStack = count($aStack);
385-
386-
if ($iStack > $iTruncate) {
387-
$iRemaining = $iStack - $iTruncate;
388-
$aStack = array_slice($aStack, 0, 5);
389-
$aStack[] = [
390-
"__TRUNCATED__" => "$iRemaining entries cut from $iStack stack entries for brevity"
391-
];
392-
}
393-
394-
$aStackCopy = [];
395-
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
396-
if (isset($aItem['args'])) {
397-
$aItem['args'] = self::replaceObjects($aItem['args']);
398-
}
399-
$aStackCopy[] = $aItem;
400-
}
382+
$oWhoops = new \Whoops\Run;
383+
$oWhoops->allowQuit(false);
384+
$oWhoops->writeToOutput(false);
385+
$oWhoopsHandler = new \Whoops\Handler\JsonResponseHandler();
386+
$oWhoopsHandler->addTraceToOutput(true);
387+
$oWhoops->pushHandler($oWhoopsHandler);
401388

402389
$aContext['--exception'] = [
403390
'type' => get_class($oThrowable),
404391
'code' => $oThrowable->getCode(),
405392
'message' => $oThrowable->getMessage(),
406393
'file' => $oThrowable->getFile(),
407394
'line' => $oThrowable->getLine(),
408-
'stack' => json_encode($aStackCopy)
395+
'stack' => $oWhoops->handleException($oThrowable)
409396
];
410397

411398
$aContext['--span'] = [

0 commit comments

Comments
 (0)