-
Notifications
You must be signed in to change notification settings - Fork 574
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 TriggerLevelWriter #602
Merged
Merged
Conversation
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
mitar
force-pushed
the
TriggerLevelWriter
branch
2 times, most recently
from
October 16, 2023 20:04
079d901
to
54caddb
Compare
In my own code, I then made: func WithContext(ctx context.Context, writer io.Writer, level, conditionalLevel, triggerLevel zerolog.Level) (context.Context, func(), func()) {
w := zerolog.NewTriggerLevelWriter(
writer,
conditionalLevel,
triggerLevel,
)
ctxLogger := zerolog.New(w).Level(level).With().Timestamp().Logger()
closeCtx := func() {
_ = w.Close()
}
trigger := func() {
_ = w.Trigger()
}
return ctxLogger.WithContext(ctx), closeCtx, trigger
} One has then to call And I then have: func NewHandler(writer io.Writer, level, conditionalLevel, triggerLevel zerolog.Level)) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ctx, closeCtx, trigger := WithContext(req.Context(), writer, level, conditionalLevel, triggerLevel)
defer closeCtx()
panicking := true
defer func() {
if panicking {
trigger()
}
}()
req = req.WithContext(ctx)
next.ServeHTTP(w, req)
panicking = false
})
}
} You can find them in my zerolog wrapper package. |
rs
reviewed
Oct 20, 2023
mitar
force-pushed
the
TriggerLevelWriter
branch
from
November 21, 2023 11:36
54caddb
to
a468d44
Compare
rs
reviewed
Nov 21, 2023
mitar
force-pushed
the
TriggerLevelWriter
branch
from
November 21, 2023 16:01
a468d44
to
8d131fd
Compare
@rs: I addressed your review comments. |
rs
reviewed
Nov 21, 2023
mitar
force-pushed
the
TriggerLevelWriter
branch
from
November 21, 2023 16:15
8d131fd
to
32c03ed
Compare
madkins23
pushed a commit
to madkins23/zerolog
that referenced
this pull request
Mar 2, 2024
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.
Fixes #583.