From 1cb39eedb5949989df860441e3b0bd3bcf0c2a0e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 13 Dec 2014 13:53:24 +0000 Subject: [PATCH] Allow including stack traces in line formatter, fixes #466 --- src/Monolog/Formatter/LineFormatter.php | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index f6055da5..12363ea3 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -28,6 +28,7 @@ class LineFormatter extends NormalizerFormatter protected $format; protected $allowInlineLineBreaks; protected $ignoreEmptyContextAndExtra; + protected $includeStacktraces; /** * @param string $format The format of the message @@ -43,6 +44,24 @@ class LineFormatter extends NormalizerFormatter parent::__construct($dateFormat); } + public function includeStacktraces($include = true) + { + $this->includeStacktraces = $include; + if ($this->includeStacktraces) { + $this->allowInlineLineBreaks = true; + } + } + + public function allowInlineLineBreaks($allow = true) + { + $this->allowInlineLineBreaks = $allow; + } + + public function ignoreEmptyContextAndExtra($ignore = true) + { + $this->ignoreEmptyContextAndExtra = $ignore; + } + /** * {@inheritdoc} */ @@ -99,7 +118,12 @@ class LineFormatter extends NormalizerFormatter } while ($previous = $previous->getPrevious()); } - return '[object] ('.get_class($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')'; + $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(); + } + + return $str; } protected function convertToString($data)