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
Chaining WithContext call is broken #116
Comments
Any idea on the issue? I like the project so far, but this stinks. I believe Logger should stay the same (to keep backward compatibility) and another function which returns *Logger is needed. How about |
Would it perhaps be better to change Line 27 in 9cd6f6e
Since the current code don't seam to handle the I don't think there should be much performance hit, but this can presumably be benchmarked. From what I can see, the logger is 88 bytes as of v1.11.0. package main
import (
"os"
"unsafe"
"github.com/rs/zerolog"
)
func main() {
l := zerolog.New(os.Stdout)
l.Info().Msgf("size if l is %d", unsafe.Sizeof(l))
l = l.With().Str("foo", "bar").Int("baz", 42).Logger()
l.Info().Msgf("size if l is %d", unsafe.Sizeof(l))
} Output:
|
It's 2021. Is there any chance this issue will be fixed? |
Feel free to submit a PR. |
Can the README at least be edited to show this part is wrong ctx := log.With().Str("component", "module").Logger().WithContext(ctx)
log.Ctx(ctx).Info().Msg("hello world")
// Output: {"component":"module","level":"info","message":"hello world"} |
A fix would be preferred. I have no time to work on it, so any PR is welcome. |
I have submitted a PR, checked have passed. I'm just waiting for a maintainer to approve and hopefully merge. 🤞🏼 |
#81 broke clients that chain
WithContext
calls. According to the docs, I expect the following program to compile (lifted from #80):but it fails:
Reason being that variables in go are addressable but return values from functions are not.
The current workaround is this:
Output:
The text was updated successfully, but these errors were encountered: