Skip to content

Commit

Permalink
Fix: Limitations of WordPressHandler regarding formatters, whereas fo…
Browse files Browse the repository at this point in the history
…rmatted data was only respected in the 'extra' part of the records, but not for 'message' or 'context'.

Updated: CHANGELOG.md, composer.json
  • Loading branch information
Grapestain authored and BenceSzalai committed Oct 14, 2020
1 parent cd3a69b commit 3f9b934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased v2]

## [2.0.1] - 2020-10-15
### Fixed
- Limitations of WordPressHandler regarding formatters, whereas formatted data was only respected in the 'extra' part of the records, but not for 'message' or 'context' (https://github.com/bradmkjr/monolog-wordpress/issues/11). **Note:** the time column still does not follow the formatted datetime to keep compatibility with existing deployments.

## [2.0.0] - 2020-04-11
### Changed
- This package now requires Monolog v2 or later
- Minimum required PHP version is 7.1 because of the same constraint in Monolog v2


## [Unreleased v1]

## [v1 changes after v2 release]
V1 is continued to be updated for continued support for Monolog v1 and PHP versions <7.1. Meaningful changes are going to be applied to both V1 and master branches. Changes made to the V1 branch however not going to be listed here between v1.6.4 and v2.0.0. For those changes please refer to the Changelog of the V1 branch.

## [1.6.4] - 2020-04-11
### Fixed
Expand Down Expand Up @@ -47,9 +50,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
No changelog had been maintained up to this point. Refer to the GIT commit history for more details.


[Unreleased v2]: https://github.com/bradmkjr/monolog-wordpress/compare/2.0.0...HEAD
[Unreleased v2]: https://github.com/bradmkjr/monolog-wordpress/compare/2.0.1...HEAD
[2.0.1]: https://github.com/bradmkjr/monolog-wordpress/tree/2.0.1
[2.0.0]: https://github.com/bradmkjr/monolog-wordpress/tree/2.0.0
[Unreleased v1]: https://github.com/bradmkjr/monolog-wordpress/compare/1.6.4...v1
[v1 changes after v2 release]: https://github.com/bradmkjr/monolog-wordpress/compare/1.6.4...v2
[1.6.4]: https://github.com/bradmkjr/monolog-wordpress/tree/1.6.4
[1.6.3]: https://github.com/bradmkjr/monolog-wordpress/tree/1.6.3
[1.6.2]: https://github.com/bradmkjr/monolog-wordpress/tree/1.6.2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["wordpress", "log", "logging", "monolog", "mysql", "database"],
"homepage": "https://github.com/bradmkjr/monolog-wordpress",
"license": "MIT",
"version": "2.0.0",
"version": "2.0.1",
"authors": [
{
"name": "Bradford Knowlton",
Expand Down
15 changes: 9 additions & 6 deletions src/WordPressHandler/WordPressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,27 @@ protected function write(array $record): void
$this->initialize($record);
}
//'context' contains the array
$contentArray = array_merge(array(
$contentArray = array(
'channel' => $record['channel'],
'level' => $record['level'],
'message' => $record['message'],
'message' => (isset($record['formatted']['message'])) ? $record['formatted']['message'] : $record['message'],
'time' => $record['datetime']->format('U')
), $record['context']);
);

// extra out formatted or unformatted extra values
// Make sure to use the formatted values for context and extra, if available
$recordExtra = (isset($record['formatted']['extra'])) ? $record['formatted']['extra'] : $record['extra'];
$recordContext = (isset($record['formatted']['context'])) ? $record['formatted']['context'] : $record['context'];

$recordContExtra = array_merge( $recordExtra, $recordContext );

// json encode values as needed
array_walk($recordExtra, function(&$value, $key) {
array_walk($recordContExtra, function(&$value, $key) {
if(is_array($value) || $value instanceof \Traversable) {
$value = json_encode($value);
}
});

$contentArray = $contentArray + $recordExtra;
$contentArray = $contentArray + $recordContExtra;

if(count($this->additionalFields) > 0) {
//Fill content array with "null" values if not provided
Expand Down

0 comments on commit 3f9b934

Please sign in to comment.