diff --git a/CHANGELOG.md b/CHANGELOG.md index c830017..824e820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -- Fixes for context and other data handling + +## [1.6.5] - 2020-04-11 +### 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. ## [1.6.4] - 2020-04-11 ### Fixed @@ -39,7 +42,8 @@ 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]: https://github.com/bradmkjr/monolog-wordpress/compare/1.6.4...v1 +[Unreleased]: https://github.com/bradmkjr/monolog-wordpress/compare/1.6.5...v1 +[1.6.5]: https://github.com/bradmkjr/monolog-wordpress/tree/1.6.5 [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..e684251 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": "^1.6.4" ``` # Usage diff --git a/composer.json b/composer.json index f2e026e..b6383c3 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": "1.6.4", + "version": "1.6.5", "authors": [ { "name": "Bradford Knowlton", diff --git a/src/WordPressHandler/WordPressHandler.php b/src/WordPressHandler/WordPressHandler.php index 3ba73a6..8fce80c 100644 --- a/src/WordPressHandler/WordPressHandler.php +++ b/src/WordPressHandler/WordPressHandler.php @@ -145,24 +145,27 @@ protected function write(array $record) $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