Repository navigation
Add Manager.SetLogger and WithDeferredLogger: the logger configured by the config itself - #52
Merged
Merged
Conversation
…red by the config itself Signed-off-by: Dmitriy Aleksandrov <goodmobiledevices@gmail.com>
Signed-off-by: Dmitriy Aleksandrov <goodmobiledevices@gmail.com>
…Logger Signed-off-by: Dmitriy Aleksandrov <goodmobiledevices@gmail.com>
…its level Signed-off-by: Dmitriy Aleksandrov <goodmobiledevices@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 31 32 +1
Lines 2581 2630 +49
=========================================
+ Hits 2581 2630 +49 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Benchmark diff:
|
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 logger is often configured by the config, but the config is parsed by the manager that already needs the logger.
WithDeferredLoggerkeeps the log records in memory, andManager.SetLoggerwrites them to the logger created from the parsed config.SetLoggeris safe for concurrent use: the logger is stored inatomic.Pointer, the kept records are written under the mutex, the records written concurrently wait for them, and the loggers taken beforeSetLogger(byParserunning at the same time) write to the current logger of the manager. Nothing is lost, the order is kept.SetLogger(nil)disables logging.WithDeferredLoggernothing is kept,SetLoggeronly replaces the logger; the behaviour of the existing code is not changed.ExampleWithDeferredLoggerwith slog (Go 1.21+), the example service creates its logger from the config and follows the changes of the level, checked by hand with the change ofconfig.yaml.SetLoggerwith concurrentParseand writers.