Skip to content

Commit

Permalink
Implement optional replacement of newline characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Jan 28, 2017
1 parent 8a0f039 commit ba21038
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 15 additions & 0 deletions src/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit ba21038

Please sign in to comment.