Skip to content

Commit

Permalink
Merge pull request #12 from BenceSzalai/v1
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 82504c3 + 65b3f04 commit c8c1fe2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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": "^1.6.4"
```

# 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": "1.6.4",
"version": "1.6.5",
"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)
$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 c8c1fe2

Please sign in to comment.