forked from sirupsen/logrus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sirupsen#913 from sirupsen/example_caller_prettyfier
Example caller prettyfier
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters