Skip to content

Commit

Permalink
Merge pull request #13 from BenceSzalai/master
Browse files Browse the repository at this point in the history
Fixed some issues with Monolog Formatter compatibility
  • Loading branch information
BenceSzalai authored Oct 15, 2020
2 parents 9fd5afe + 3f9b934 commit 86b3bd6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 86b3bd6

Please sign in to comment.