-
-
Notifications
You must be signed in to change notification settings - Fork 136
Logger local named tags [WIP] #301
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,7 +211,15 @@ def tags | |
| end | ||
|
|
||
| def named_tags | ||
| SemanticLogger.named_tags | ||
| SemanticLogger.named_tags.merge(@named_tags || {}) | ||
| end | ||
|
|
||
| # Sets named tags which are local to the logger instance. | ||
| # | ||
| # 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 commentThe reason will be displayed to describe this comment to others. Learn more. Is it just me or this feels a little strange? |
||
| end | ||
|
|
||
| # Returns the list of tags pushed after flattening them out and removing blanks | ||
|
|
@@ -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 commentThe 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. 🤔 |
||
|
|
||
| should_log = | ||
| if exception.nil? && payload.nil? && message.is_a?(Hash) | ||
| # All arguments as a hash in the message. | ||
|
|
||