cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.12k stars 496 forks source link

This caller file path and line number is not the expected ones #1089

Closed jemygraw closed 5 months ago

jemygraw commented 5 months ago

Describe the bug

I want the logger to print the file path and line number where it is called to track problems. But the current output file path and line number is the logger files in which the logger functions are defined.

To Reproduce

Steps to reproduce the behavior:

stdLogger := logrus.New()
stdLogger.SetReportCaller(true)

---

hlog.Debugf("xxx")

Expected behavior

print the file path and line number of the file in which hlog.Debugf is called.

Screenshots

The current output which is not what I expected.

github.com/hertz-contrib/logger/logrus@v1.0.1/logger.go:91

Way to fix I think we should not wrap the logger in a new function in this file.

https://github.com/cloudwego/hertz/blob/develop/pkg/common/hlog/default.go#L28

They should be defined like this.

var Fatal = logger.Fatal
li-jin-gou commented 5 months ago

cc @rogerogers

li-jin-gou commented 5 months ago

refer to https://github.com/cloudwego/hertz-examples/blob/main/hlog/logrus/main.go#L105 and because of the additional layer of encapsulation, the line numbers of logrus have changed and require additional configuration.