diff --git a/README.md b/README.md index 89706b1..2a06626 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ return [ (Since 1.2.0) * (*string|null*) `$replaceNewline` a string that should replace all newline characters in a log message. Default ist `null` for no replacement. (Since 1.1.0) + * (*string|null*) `$replaceParagraph` a string that should replace all paragraph characters in a log message. + Default ist `null` for no replacement. * (*bool*) `$disableTimestamp` whether to omit the timestamp prefix. The default is `false` which will prepend every message with a timestamp generated by `yii\log\Target::getTime()`. (Since 1.3.0) * (*string*) `$prefixString` a string that will be prefixed to every message at the first position diff --git a/src/Target.php b/src/Target.php index 3a2ceae..6b3b0b1 100644 --- a/src/Target.php +++ b/src/Target.php @@ -22,6 +22,12 @@ class Target extends BaseTarget */ public $replaceNewline; + /** + * @var string|null a string that should replace all paragraph characters + * in a log message. Default ist `null` for no replacement. + */ + public $replaceParagraph; + /** * @var bool whether to disable the timestamp. The default is `false` which * will prepend every message with a timestamp created with @@ -137,9 +143,13 @@ public function export() public function formatMessage($message) { $text = $this->prefixString . trim(parent::formatMessage($message)); - return $this->replaceNewline === null ? + $textAfterReplacingNewline = $this->replaceNewline === null ? $text : str_replace("\n", $this->replaceNewline, $text); + + return $this->replaceParagraph === null ? + $textAfterReplacingNewline : + str_replace("\r\n", $this->replaceParagraph, $textAfterReplacingNewline); } /**