From 5c2b39a4f8d3edd100748d226a77acb4649d79ec Mon Sep 17 00:00:00 2001 From: David Bariod Date: Sun, 3 Mar 2019 11:52:04 +0100 Subject: [PATCH 1/2] Remove debug trace --- json_formatter.go | 1 - 1 file changed, 1 deletion(-) diff --git a/json_formatter.go b/json_formatter.go index c494d07..ae95040 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -93,7 +93,6 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) if f.CallerPrettyfier != nil { funcVal, fileVal = f.CallerPrettyfier(entry.Caller) - fmt.Println(funcVal, fileVal) } if funcVal != "" { data[f.FieldMap.resolve(FieldKeyFunc)] = funcVal From 99a5172d62d45e607945ff99722c24a7db95e7a0 Mon Sep 17 00:00:00 2001 From: David Bariod Date: Sun, 3 Mar 2019 11:53:51 +0100 Subject: [PATCH 2/2] Add and example for CallerPrettyfier --- example_custom_caller_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 example_custom_caller_test.go diff --git a/example_custom_caller_test.go b/example_custom_caller_test.go new file mode 100644 index 0000000..e0023b9 --- /dev/null +++ b/example_custom_caller_test.go @@ -0,0 +1,28 @@ +package logrus_test + +import ( + "os" + "path" + "runtime" + "strings" + + "github.com/sirupsen/logrus" +) + +func ExampleCustomFormatter() { + 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: + // {"file":"example_custom_caller_test.go","func":"ExampleCustomFormatter","level":"info","msg":"example of custom format caller"} +}