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.

44 lines
902 B

  1. package common
  2. import (
  3. stdlog "log"
  4. "os"
  5. "github.com/op/go-logging"
  6. )
  7. var Log = logging.MustGetLogger("main")
  8. func init() {
  9. // Customize the output format
  10. logging.SetFormatter(logging.MustStringFormatter("▶ %{level:.1s} 0x%{id:x} %{message}"))
  11. // Setup one stdout and one syslog backend.
  12. logBackend := logging.NewLogBackend(os.Stderr, "", stdlog.LstdFlags|stdlog.Lshortfile)
  13. logBackend.Color = true
  14. syslogBackend, err := logging.NewSyslogBackend("")
  15. if err != nil {
  16. panic(err)
  17. }
  18. // Combine them both into one logging backend.
  19. logging.SetBackend(logBackend, syslogBackend)
  20. // Test
  21. /*
  22. Log.Debug("debug")
  23. Log.Info("info")
  24. Log.Notice("notice")
  25. Log.Warning("warning")
  26. Log.Error("error")
  27. */
  28. }
  29. var Debug = Log.Debug
  30. var Info = Log.Info
  31. var Notice = Log.Notice
  32. var Warning = Log.Warning
  33. var Warn = Log.Warning
  34. var Error = Log.Error
  35. var Critical = Log.Critical