-
Notifications
You must be signed in to change notification settings - Fork 290
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
Add withMetadata() convenience function for adding multiple metadata k/v pairs to a Logger #322
Open
gabbifish
wants to merge
1
commit into
apple:main
Choose a base branch
from
gabbifish:add-withMetadata-convenience-func
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,20 @@ extension Logger { | |
} | ||
} | ||
|
||
/// Convenience function for merging multiple metadata items into a Logger's existing metadata. | ||
/// | ||
/// - parameters: | ||
/// - metadata: The metadata to merge into a Logger's existing metadata. | ||
/// | ||
/// - note: Logging metadata behaves as a value that means a change to the logging metadata will only affect the | ||
/// very `Logger` it was changed on. | ||
@inlinable | ||
public mutating func mergeMetadata(_ metadata: Logger.Metadata) { | ||
metadata.forEach { (key, value) in | ||
self.handler[metadataKey: key] = value | ||
} | ||
Comment on lines
+178
to
+180
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. I suspect in many (all?) handler implementations this will acquire and release a lock for each value we update. Can we call |
||
} | ||
|
||
/// Get or set the log level configured for this `Logger`. | ||
/// | ||
/// - note: `Logger`s treat `logLevel` as a value. This means that a change in `logLevel` will only affect this | ||
|
This file contains 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
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.
Can we add the
uniquingKeysWith
parameter as well à la Dictionary?