I'm using logrus OS which works as expected, now we have a requirement to add to the logger output the file and the function which from where you put the logger call,
we need it to be something like
File log-ut-usage
func main(){
logs := lts.InitLogger("test","1","debug")
logs.Debugf("test 123")
....
}
This is the required output
{"file":"log-ut-usage/main.go:21","function":"main","level":"warn","test 123":"ddd","timestamp":"2019-10-02T09:21:39.309559Z"}
currently we got the file and function of the
file logger.go
func InitLog(label string) LoggerI {
loggerImpl = &logrus.Logger{
Out: os.Stdout,
Level: level,
ReportCaller: true,
Formatter: &logrus.JSONFormatter{
TimestampFormat: timestampFormat,
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
},
},
}
This is the (unwanted) output
{"file":"logger.go","func":"InitLog","level":"debug","msg":"test 123","time":"2019-10-02 12:21:39"}
I dont want to get the file logger.go where we coded the json formater, I want to get the file that with the usage of the logger .