Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replacing paragraph characters attribute - replaceParagraph #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down