logrus
logrus copied to clipboard
SetReportCaller only returns logrus log file instead of where the error occured
This is my func that instantiates a new logrus:
func NewLogger() *StdLogger {
baseLogger := logrus.New()
stdLogger := &StdLogger{baseLogger}
if beego.AppConfig.String("runmode") != "dev" {
stdLogger.SetOutput(os.Stdout)
stdLogger.SetLevel(logrus.DebugLevel)
} else {
stdLogger.SetLevel(logrus.InfoLevel)
}
stdLogger.SetReportCaller(true)
// prettyfier based on an official example
stdLogger.Formatter = &logrus.JSONFormatter{
PrettyPrint: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
s := strings.Split(f.Function, ".")
funcname := s[len(s)-1]
_, filename := path.Split(f.File)
return funcname, filename
},
}
return stdLogger
}
From it, I defined a few other log functions such as this one for common errors:
func (log *StdLogger) LogError(arg string) {
log.Errorf(commonError.message, arg)
}
However, the file
and func
properties on the logs will only refer to my log package itself, that is, the very LogError func above instead of where I captured it with an err != nil
check. I'm currently on go 1.18, logrus@latest, saw a buch of other resolved issues where this problem seems to have been solved, but it's happening to me nonetheless.
Sembra che questo livello di avvolgimento della libreria di classi sia la causa di questo problema, l'hai risolto per favore?
After debugging, the constant knownLogrusFrames=7 in yywrentry.go can be changed to
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Have you found a solution to this problem?