You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_custom_caller_test.go 680B

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