logging.go 626 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "time"
  4. "github.com/tal-tech/go-zero/core/logx"
  5. )
  6. func foo() {
  7. logx.WithDuration(time.Second).Error("world")
  8. }
  9. func main() {
  10. c := logx.LogConf{
  11. Mode: "console",
  12. Path: "logs",
  13. }
  14. logx.MustSetup(c)
  15. defer logx.Close()
  16. logx.Info("info")
  17. logx.Error("error")
  18. logx.ErrorStack("hello")
  19. logx.Errorf("%s and %s", "hello", "world")
  20. logx.Severef("%s severe %s", "hello", "world")
  21. logx.Slowf("%s slow %s", "hello", "world")
  22. logx.Statf("%s stat %s", "hello", "world")
  23. logx.WithDuration(time.Minute + time.Second).Info("hello")
  24. logx.WithDuration(time.Minute + time.Second).Error("hello")
  25. foo()
  26. }