Improve HookLogFactory::fromString() - #124
Merged
Merged
Conversation
When there are exactly 2 arguments, and the second is an array, make it equivalent to HookLogFactory::fromArray() where the message key is the original 1st argument. See #123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
The documentation states that when the log record's “context” array has a key "channel", Wonolog uses that context value as the log record channel.
This is true when an action hook uses only one argument as array, for example:
but it is not true when passing the message as first argument as string:
Reported via #123
The cause
The problem is that the source for "channel" (but also "level") when creating a log entry from a hook's arguments is the first argument passed to the hook.
The solution
Iit makes sense that when exactly 2 arguments are passed, and the second argument is an array containing relevant info, we use that info. So, the two snippets above are equivalent.
However, when multiple arguments are passed, or when the second argument is an array that does not contain relevant info ("level", "channel", "context") nothing changes, keeping backward compatibility.
This PR addresses this, adding unit tests.
Note: a second commit in this PR addresses some PHPStan errors in a n unrelated test file (
AdvancedConfigTest.php) so that the CI could be green, facilitating the merge.