Skip to content

Instantly share code, notes, and snippets.

@grambas
Created January 18, 2024 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grambas/f4a2d8dd8fbbf30f41a658404edd9e1a to your computer and use it in GitHub Desktop.
Save grambas/f4a2d8dd8fbbf30f41a658404edd9e1a to your computer and use it in GitHub Desktop.
Log stack trace as string too for exceptions
<?php
declare(strict_types=1);
namespace App\Monolog;
use Throwable;
/**
* log stack trace instead of exception class
*/
class StackTraceProcessor
{
public function __invoke(array $record): array
{
foreach($record['context'] as $key => $data) {
if ($data instanceof Throwable && !in_array('backtrace', $record['context'], true)) {
$record['extra']['backtrace'] = $data->getTraceAsString();
unset($record['context'][$key]);
}
}
return $record;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment