2
0

logger.go 973 B

1234567891011121314151617181920212223242526272829303132333435
  1. package internal
  2. import (
  3. "os"
  4. "gopkg.in/op/go-logging.v1"
  5. )
  6. // InitLogger initilizes logging format and level
  7. func InitLogger(verbose, debug, withSystemd bool) {
  8. var fmtString string
  9. if withSystemd {
  10. fmtString = "[%{level:.6s}] %{message}"
  11. } else {
  12. if debug {
  13. fmtString = "%{color}[%{time:06-01-02 15:04:05}][%{level:.6s}][%{shortfile}]%{color:reset} %{message}"
  14. } else {
  15. fmtString = "%{color}[%{time:06-01-02 15:04:05}][%{level:.6s}]%{color:reset} %{message}"
  16. }
  17. }
  18. format := logging.MustStringFormatter(fmtString)
  19. logging.SetFormatter(format)
  20. logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0))
  21. if debug {
  22. logging.SetLevel(logging.DEBUG, "tunasync")
  23. logging.SetLevel(logging.DEBUG, "tunasynctl-cmd")
  24. } else if verbose {
  25. logging.SetLevel(logging.INFO, "tunasync")
  26. logging.SetLevel(logging.INFO, "tunasynctl-cmd")
  27. } else {
  28. logging.SetLevel(logging.NOTICE, "tunasync")
  29. logging.SetLevel(logging.NOTICE, "tunasynctl-cmd")
  30. }
  31. }