2
0

logger.go 696 B

12345678910111213141516171819202122232425262728
  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. fmtString = "%{color}[%{time:06-01-02 15:04:05}][%{level:.6s}][%{shortfile}]%{color:reset} %{message}"
  13. }
  14. format := logging.MustStringFormatter(fmtString)
  15. logging.SetFormatter(format)
  16. logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0))
  17. if debug {
  18. logging.SetLevel(logging.DEBUG, "tunasync")
  19. } else if verbose {
  20. logging.SetLevel(logging.INFO, "tunasync")
  21. } else {
  22. logging.SetLevel(logging.NOTICE, "tunasync")
  23. }
  24. }