Skip to content

Commit

Permalink
[+] Close #15. Allow to extract exceptions' trace (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturf authored Mar 3, 2020
1 parent 6a61b7e commit 5ca1a69
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/PsrTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class PsrTarget extends Target implements LoggerAwareInterface
*/
public $addTimestampToContext = false;

/**
* @var bool If enabled, exception's trace will extract into `trace` property
*/
public $extractExceptionTrace = false;

private $_levelMap = [
Logger::LEVEL_ERROR => LogLevel::ERROR,
Logger::LEVEL_WARNING => LogLevel::WARNING,
Expand Down Expand Up @@ -98,7 +103,12 @@ public function export()
// exceptions may not be serializable if in the call stack somewhere is a Closure
if ($text instanceof \Throwable || $text instanceof \Exception) {
$context['exception'] = $text;
$text = (string)$text;
if ($this->extractExceptionTrace) {
$context['trace'] = explode(PHP_EOL, $text->getTraceAsString());
$text = $text->getMessage();
} else {
$text = (string)$text;
}
} else {
$text = VarDumper::export($text);
}
Expand Down

1 comment on commit 5ca1a69

@ilyaplot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Немного нелепо выглядит $text instanceof Exception )

Please sign in to comment.