From ba21038819d2c5190caa30f62f9c2408eb1b06d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Sat, 28 Jan 2017 09:01:44 +0100 Subject: [PATCH] Implement optional replacement of newline characters --- CHANGELOG.md | 10 +++++++++- README.md | 6 ++++++ src/Target.php | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 270df0a..72d4a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 1.1.0 + + * New feature: `$replaceNewline` to optionally replace newline characters in log messages + +## 1.0.0 + +First stable release. + ## 0.0.1 -Initial version +Initial version. diff --git a/README.md b/README.md index e6ad61c..c4fc8fe 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,9 @@ return [ ], ], ``` + +## Configuration Options + + * `$url` *string* the URL to use. See http://php.net/manual/en/wrappers.php for details. + * `$replaceNewline` *string|null* a string that should replace all newline characters in a log message. + Default ist `null` for no replacement. diff --git a/src/Target.php b/src/Target.php index 77f7d0f..04a30b9 100644 --- a/src/Target.php +++ b/src/Target.php @@ -14,6 +14,12 @@ class Target extends BaseTarget */ public $url; + /** + * @var string|null a string that should replace all newline characters in a log message. + * Default ist `null` for no replacement. + */ + public $replaceNewline; + /** * Writes a log message to the given target URL * @throws InvalidConfigException if unable to open the stream for writing @@ -30,4 +36,13 @@ public function export() fwrite($fp, $text); fclose($fp); } + + /** + * @inheritdoc + */ + public function formatMessage($message) + { + $text = parent::formatMessage($message); + return $this->replaceNewline===null ? $text : str_replace("\n", $this->replaceNewline, $text); + } }