1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Include stacktraces for "previous" excpetions in LineFormatter

This commit is contained in:
Matthias Pigulla
2018-06-18 17:41:09 +02:00
parent 4e96288c15
commit c04f66ed54
2 changed files with 14 additions and 8 deletions

View File

@@ -126,18 +126,14 @@ class LineFormatter extends NormalizerFormatter
protected function normalizeException(\Throwable $e, int $depth = 0): string
{
$previousText = '';
$str = $this->formatException($e);
if ($previous = $e->getPrevious()) {
do {
$previousText .= ', '.get_class($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
$str .= "\n[previous exception] " . $this->formatException($previous);
} while ($previous = $previous->getPrevious());
}
$str = '[object] ('.get_class($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
if ($this->includeStacktraces) {
$str .= "\n[stacktrace]\n".$e->getTraceAsString()."\n";
}
return $str;
}
@@ -166,4 +162,14 @@ class LineFormatter extends NormalizerFormatter
return str_replace(["\r\n", "\r", "\n"], ' ', $str);
}
private function formatException(\Throwable $e): string
{
$str = '[object] (' . get_class($e) . '(code: ' . $e->getCode() . '): ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . ')';
if ($this->includeStacktraces) {
$str .= "\n[stacktrace]\n" . $e->getTraceAsString() . "\n";
}
return $str;
}
}