1package logrus_test 2 3import ( 4 "os" 5 "path" 6 "runtime" 7 "strings" 8 9 "github.com/sirupsen/logrus" 10) 11 12func ExampleJSONFormatter_CallerPrettyfier() { 13 l := logrus.New() 14 l.SetReportCaller(true) 15 l.Out = os.Stdout 16 l.Formatter = &logrus.JSONFormatter{ 17 DisableTimestamp: true, 18 CallerPrettyfier: func(f *runtime.Frame) (string, string) { 19 s := strings.Split(f.Function, ".") 20 funcname := s[len(s)-1] 21 _, filename := path.Split(f.File) 22 return funcname, filename 23 }, 24 } 25 l.Info("example of custom format caller") 26 // Output: 27 // {"file":"example_custom_caller_test.go","func":"ExampleJSONFormatter_CallerPrettyfier","level":"info","msg":"example of custom format caller"} 28} 29