logrus/example_custom_caller_test.go

29 lines
676 B
Go
Raw Normal View History

2019-03-03 13:53:51 +03:00
package logrus_test
import (
"os"
"path"
"runtime"
"strings"
2022-12-21 15:59:06 +03:00
"git.internal/re/logrus"
2019-03-03 13:53:51 +03:00
)
func ExampleJSONFormatter_CallerPrettyfier() {
2019-03-03 13:53:51 +03:00
l := logrus.New()
l.SetReportCaller(true)
l.Out = os.Stdout
l.Formatter = &logrus.JSONFormatter{
DisableTimestamp: 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
},
}
l.Info("example of custom format caller")
// Output:
2019-10-14 23:23:44 +03:00
// {"file":"example_custom_caller_test.go","func":"ExampleJSONFormatter_CallerPrettyfier","level":"info","msg":"example of custom format caller"}
2019-03-03 13:53:51 +03:00
}