Caller, how to get the correct line number #1154
LazarenkoA
started this conversation in
General
Replies: 3 comments
-
I wrote a question and came up with a solution, in principle, this is no longer an actual question |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hello 👋 Couldn't you only do this? func test2() {
l := logger.WithOptions(zap.AddCallerSkip(-1)).Sugar()
l.Info("test")
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi, I have such a project structure
..
|_main.go
|_logger
|___logger.go
body logger.go:
main.go:
result:
{"level":"INFO","time":"2022-08-19T22:22:42+03:00","caller":"logger/logger.go:44","msg":"test"}
"caller":"logger/logger.go:44"
- not correctto fix this, you need to add option
zap.AddCallerSkip(1)
after that, the result is{"level":"INFO","time":"2022-08-19T22:25:41+03:00","caller":"test/main.go:21","msg":"test"}
ok, but what if in program use local logger and global logger
it turns out that the caller is incorrect again
{"level":"INFO","time":"2022-08-19T22:33:26+03:00","caller":"test/main.go:16","msg":"test","value":2}
what can you come up with in this situation so that the caller is always correct?
Beta Was this translation helpful? Give feedback.
All reactions