mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 21:56:31 +02:00
When newlines are allowed in LineFormatter, unpack json_encoded blobs containing newlines into multiline strings, fixes #752
This commit is contained in:
@@ -130,7 +130,7 @@ class LineFormatter extends NormalizerFormatter
|
|||||||
|
|
||||||
$str = '[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) {
|
if ($this->includeStacktraces) {
|
||||||
$str .= "\n[stacktrace]\n".$e->getTraceAsString();
|
$str .= "\n[stacktrace]\n".$e->getTraceAsString()."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
@@ -152,6 +152,10 @@ class LineFormatter extends NormalizerFormatter
|
|||||||
protected function replaceNewlines($str)
|
protected function replaceNewlines($str)
|
||||||
{
|
{
|
||||||
if ($this->allowInlineLineBreaks) {
|
if ($this->allowInlineLineBreaks) {
|
||||||
|
if (0 === strpos($str, '{')) {
|
||||||
|
return str_replace(['\r', '\n'], ["\r", "\n"], $str);
|
||||||
|
}
|
||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -137,6 +137,24 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).')"} []'."\n", $message);
|
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).')"} []'."\n", $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDefFormatWithExceptionAndStacktrace()
|
||||||
|
{
|
||||||
|
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||||
|
$formatter->includeStacktraces();
|
||||||
|
$message = $formatter->format([
|
||||||
|
'level_name' => 'CRITICAL',
|
||||||
|
'channel' => 'core',
|
||||||
|
'context' => ['exception' => new \RuntimeException('Foo')],
|
||||||
|
'datetime' => new \DateTimeImmutable,
|
||||||
|
'extra' => [],
|
||||||
|
'message' => 'foobar',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$path = str_replace('\\/', '/', json_encode(__FILE__));
|
||||||
|
|
||||||
|
$this->assertRegexp('{^\['.date('Y-m-d').'] core\.CRITICAL: foobar \{"exception":"\[object] \(RuntimeException\(code: 0\): Foo at '.preg_quote(substr($path, 1, -1)).':'.(__LINE__ - 8).'\)\n\[stacktrace]\n#0}', $message);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDefFormatWithPreviousException()
|
public function testDefFormatWithPreviousException()
|
||||||
{
|
{
|
||||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||||
|
Reference in New Issue
Block a user