-
Notifications
You must be signed in to change notification settings - Fork 1
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
DefaultOtelSugaredLogger 输出的 Caller 似乎多跳了一跳? #1
Comments
将 option.go 里的默认 callskip 改为 0 之后 DefaultOtelSugaredLogger 正常了,DefaultSugaredLogger 就打印到里面去了。 {"level":"info","time":"2024-08-12 23:37:59.616","caller":"easylog/exported.go:182","msg":"hello world"}
{"level":"info","time":"2024-08-12 23:37:59.622","caller":"cmd/main.go:10","msg":"hello world"} |
l.otelSugaredLogger = otelzap.NewSugaredLogger(l.sugaredLogger.WithOptions(zap.AddCallerSkip(-1))) 这样调整了一下就正常了,但没找出原因所在🤣 |
可以通过 option.WithCallerSkip(2) 定义合适的值 easylog.InitGlobalLogger(option.WithLogLevel("info"),option.WithCallerSkip(2)) 然后直接打印日志即可 easylog.Info("hello world") full code package main
import (
"github.com/logerror/easylog"
"github.com/logerror/easylog/pkg/option"
)
func main() {
easylog.InitGlobalLogger(option.WithLogLevel("info"), option.WithCallerSkip(2))
easylog.Info("hello world")
easylog.Info("hello world")
} output {"level":"info","time":"2024-08-20 17:34:38.425","caller":"test/main.go:10","msg":"hello world"}
{"level":"info","time":"2024-08-20 17:34:38.425","caller":"test/main.go:11","msg":"hello world"} |
如果多个协程同时使用的话,easylog 的初始化跟 |
嗯 确实有可能 考虑到 ReplaceLogger 的使用较少,后续考虑加上吧 或者您可以试着完善下? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
输出结果如下:
The text was updated successfully, but these errors were encountered: