feat(log): support installing a custom logger via SetLogger#436
Open
Kybxd wants to merge 1 commit into
Open
Conversation
Add log.SetLogger / tableau.SetLogger to let callers plug in their own Printf-style logger (e.g. *zap.SugaredLogger, or a thin adapter around slog/logrus) as tableau's log destination, via a new customdriver. Once installed, subsequent log.Init calls (triggered internally by GenProto/GenConf) no longer override the custom driver, only updating the log level used for LevelEnabled. Also rename the built-in Logger struct to sugaredLogger to avoid naming collision with the new exported Logger interface, and trim a debug log in load.go that printed the entire patched message via %s.
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (60.19%) is below the target coverage (63.00%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## master #436 +/- ##
===========================================
- Coverage 75.57% 60.19% -15.39%
===========================================
Files 88 83 -5
Lines 9515 9089 -426
===========================================
- Hits 7191 5471 -1720
- Misses 1749 2949 +1200
- Partials 575 669 +94 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
Add
log.SetLogger/tableau.SetLoggerto let callers plug in their own Printf-style logger (e.g.*zap.SugaredLogger, or a thin adapter aroundslog/logrus) as tableau's log destination, via a newcustomdriver.Details
log/driver/customdriverpackage: wraps a minimalLoggerinterface (Debugf/Infof/Warnf/Errorf/DPanicf/Panicf/Fatalf) as adriver.Driver, normalizingXxx/Xxxf/Xxxwcalls into a single formatted message.log.SetLogger(logger): installs the custom driver and marks that a custom logger is active.log.Init(opts): once a custom logger has been installed viaSetLogger, subsequentInitcalls (triggered internally byGenProto/GenConf) no longer override the custom driver; they only update the log level used forLevelEnabled.Loggerstruct tosugaredLoggerto avoid a naming collision with the new exportedLoggerinterface.tableau.SetLoggerexposes the same capability at the top-level package.load.gothat previously printed the entire patched message via%s, which could produce excessive output for large messages.Tests
log/setlogger_test.gocoveringSetLoggerbehavior.log/log_test.go/log/logger_test.gofor theLogger->sugaredLoggerrename.