diff --git a/CHANGELOG.md b/CHANGELOG.md index d445e9b..5fc3a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index 24ac354..2c6faf0 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ Homepage: http://www.d-herrmann.de/projects/monolog-mysql-handler/ This is a very simple handler for monolog. This version works for custom plugin development, but I would not advise to distrubte this code in a public repository for general use on high traffic sites. You have been warned. # Installation -monolog-wordpress is available via composer. Just add the following line to your required section in composer.json and do a `php composer.phar update`. +monolog-wordpress is available via composer. Just add the following line to your required section in composer.json and do a `php composer.phar update` or your choice of composer update method. ``` -"bradmkjr/monolog-wordpress": ">1.6.3" +"bradmkjr/monolog-wordpress": "^2.0.0" ``` # Usage diff --git a/composer.json b/composer.json index 7d57b6e..dd4221a 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/WordPressHandler/WordPressHandler.php b/src/WordPressHandler/WordPressHandler.php index 1993c9b..b9b4a15 100644 --- a/src/WordPressHandler/WordPressHandler.php +++ b/src/WordPressHandler/WordPressHandler.php @@ -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