-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger local named tags [WIP] #301
base: master
Are you sure you want to change the base?
Conversation
Adds the ability to set named tags on the logger instance via the new `#named_tags=` instance method. Once set, subsequent calls to the logger that would normally emit a log entry will contain the local named tags, in addition to global ones or those added with `#tagged`. Within a `#tagged` block, logs generated by the instance will already contain the local named tags, but any other logger's entries will not.
@@ -327,6 +335,10 @@ def log_internal(level, index, message = nil, payload = nil, exception = nil) | |||
end | |||
|
|||
log = Log.new(name, level, index) | |||
|
|||
# Apply the named tags to the log entry | |||
log.named_tags = named_tags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this was the best way to handle this. Thought of maybe passing the tags to the log initializer but was conscious that might break the API. 🤔
Slightly unrelated - I noticed the filter spec on |
# Local named tags are merged into the log entry along with the thread-level ones | ||
# and those set via `#tagged` or `#with_tags`. | ||
def named_tags=(tags) | ||
(@named_tags ||= {}).merge!(tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it just me or this feels a little strange?
I'm thinking the expected behavior would be for the whole value to be overridden, right?
Issue #165
Changelog (TODO)
Pull requests will not be accepted without a description of this change under the
[unreleased]
sectionin the file
CHANGELOG
.Description of changes
Note: This isn't quite ready for prime yet but raising the draft early for some feedback and discussion.
I've taken an initial stab at this with the goal of adding the discussed functionality without breaking existing API or behavior. The proposed ideas seem to slot in nicely with current functionality in such a way that I wouldn't expect anything to break.
However, there's something I wanted to raise which I had initially taken for a given that actually turned out to be a little unintuitive, in my opinion.. This is very much an API design consideration, so your input would be valuable @reidmorrison.
Consider the following:
As the PR currently is,
"test"
would contain bothtest
andimportant
while"doing something"
would only containimportant
. This is aligned with what was discussed in the issue and it kind of makes sense. However, what got me thinking was the fact that we called#tagged
on the logger instance here, which my intuition tells me would have an additive effect on the tags already set at the logger level. In other words, add to the logs within the block, any logs already present in the logger in addition to these i'm providing now.This intuition comes from the fact that this is how things currently work today. Of course this comes from the fact that the only other tags that exist in addition to those passed to
#tagged
are those already set at the thread level. But if we are introducing this "third layer", we need to decide on which makes more sense.As it currently stands, I don't know if theres much practical difference in using
logger.tagged
vsSemanticLogger.tagged
, so I think we have two options iftagged
is called on the logger:tagged
, regardless of the receiver.tagged
tags to the logger's own logs.I think either of the two would help in keeping things consistent, though the second option would obviously be a bit more work and would definitely break current behavior.
Frankly I don't know which is better and like I mention, this is more of a design consideration. Personally I feel like the first option is the way to go, but there's a very possible chance I'm missing part of the puzzle here, so any input would be appreciated.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.