|
|
|
@ -25,6 +25,30 @@ class LogFileFormatter extends LineFormatter {
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
public function format (array $record): string {
|
|
|
|
|
return preg_replace('/((?<!\\\\)\\\\[rn])+$/', PHP_EOL, parent::format($record));
|
|
|
|
|
//region Get then remove newlines at record message end (*before* the formatting)
|
|
|
|
|
$messageEndNewlines = '';
|
|
|
|
|
$record['message'] = preg_replace_callback(
|
|
|
|
|
'/(?:(?<!\\\\)(?:\\\\[rn]|\\r|\\n))+$/',
|
|
|
|
|
function (array $match) use (&$messageEndNewlines): string {
|
|
|
|
|
$messageEndNewlines = $match[0];
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
$this->normalize($record['message'])
|
|
|
|
|
);
|
|
|
|
|
//endregion
|
|
|
|
|
//region Format the record
|
|
|
|
|
$output = parent::format($record);
|
|
|
|
|
//endregion
|
|
|
|
|
//region Remove newlines at end (introduced by context, extra or record message itself)
|
|
|
|
|
$output = preg_replace('/(?:(?<!\\\\)(?:\\\\[rn]|\\r|\\n))+$/', '', $output);
|
|
|
|
|
//endregion
|
|
|
|
|
//region Re-add the newlines of record message end
|
|
|
|
|
$output .= $messageEndNewlines;
|
|
|
|
|
//endregion
|
|
|
|
|
//region Then finally, replace manual "\r" or "\n" by theirs equivalent
|
|
|
|
|
return preg_replace(
|
|
|
|
|
'/(?:(?<!\\\\)\\\\[rn])+/', PHP_EOL, $output
|
|
|
|
|
);
|
|
|
|
|
//endregion
|
|
|
|
|
}
|
|
|
|
|
}
|