-
Notifications
You must be signed in to change notification settings - Fork 152
logger: replace WithTap with WithTee #1790
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9b4fd32
logger/zaputil: replay deferred writes through Check
paulwe 405ca56
logger: replace WithTap with WithTee
paulwe 02e7bd2
logger/zaputil: replace encoderCore with zapcore.NewCore
paulwe 613798c
logger/zaputil: drop the Encoder type parameter
paulwe d955857
logger: make the component leveler replaceable per branch
paulwe 6cba886
Merge remote-tracking branch 'origin/main' into logger-with-tee
paulwe 81d557d
changeset: cover WithComponentLeveler
paulwe b2d148f
logger: tighten the tee comments
paulwe 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
8 changes: 8 additions & 0 deletions
.changeset/logger-with-tee.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "github.com/livekit/protocol": minor | ||
| "@livekit/protocol": patch | ||
| --- | ||
|
|
||
| Replace logger.WithTap with logger.WithTee, which duplicates every log entry to a caller-supplied zaputil.Tee. The tee's core is built from the level each derived logger resolves, so the copy follows component levels rather than carrying a level of its own. | ||
|
|
||
| Replace ZapLogger.WithMinLevel with WithComponentLeveler, which attaches a zaputil.ComponentLeveler to a branch of the logger tree. A leveler owns the per-component level and write-enabler cache for one configuration source and can only widen its parent, so a caller can resolve levels per (tenant, component) without rebuilding loggers on a config change. ZapLogger.Leveler exposes the leveler a branch resolves through, for use as the parent of a derived one. |
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
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
25 changes: 25 additions & 0 deletions
logger/config_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package logger | ||
|
|
||
| import ( | ||
| "io" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.uber.org/zap/zapcore" | ||
|
|
||
| "github.com/livekit/protocol/logger/zaputil" | ||
| ) | ||
|
|
||
| func TestConfigResolveComponentLevel(t *testing.T) { | ||
| conf := &Config{Level: "info", ComponentLevels: map[string]string{"rtc.room": "debug"}} | ||
| root := zaputil.NewRootComponentLeveler(zapcore.AddSync(io.Discard), conf) | ||
|
|
||
| require.True(t, root.ComponentLevel("rtc.room").Enabled(zapcore.DebugLevel)) | ||
| require.True(t, root.ComponentLevel("rtc.room.track").Enabled(zapcore.DebugLevel)) | ||
| require.False(t, root.ComponentLevel("rtc").Enabled(zapcore.DebugLevel)) | ||
| require.True(t, root.ComponentLevel("rtc").Enabled(zapcore.InfoLevel)) | ||
|
|
||
| lvl, ok := (&Config{}).ResolveComponentLevel("anything") | ||
| require.True(t, ok) | ||
| require.Equal(t, zapcore.InfoLevel, lvl) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.