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

Strip inline line breaks from LineFormatter entries.

This commit is contained in:
Gunnar Lium
2014-02-14 12:46:14 +01:00
parent 6cabe95f23
commit 2aa09265fc
2 changed files with 45 additions and 3 deletions

View File

@@ -26,14 +26,17 @@ class LineFormatter extends NormalizerFormatter
const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
protected $format;
protected $allowInlineLineBreaks;
/**
* @param string $format The format of the message
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param string $format The format of the message
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param bool $allowInlineLineBreaks Whether to allow inline line breaks in log entries
*/
public function __construct($format = null, $dateFormat = null)
public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false)
{
$this->format = $format ?: static::SIMPLE_FORMAT;
$this->allowInlineLineBreaks = $allowInlineLineBreaks;
parent::__construct($dateFormat);
}
@@ -57,6 +60,10 @@ class LineFormatter extends NormalizerFormatter
}
}
if (!$this->allowInlineLineBreaks) {
$output = $this->replaceInlineLineBreaks($output);
}
return $output;
}
@@ -98,4 +105,11 @@ class LineFormatter extends NormalizerFormatter
return str_replace('\\/', '/', @json_encode($data));
}
private function replaceInlineLineBreaks($output)
{
$suffix = substr($output, -1) === "\n" ? "\n" : '';
return trim(str_replace("\n", ' ', $output)) . $suffix;
}
}