gosuki/log.go

41 lines
963 B
Go
Raw Normal View History

2017-11-19 16:00:37 +00:00
package main
import (
"os"
logging "github.com/op/go-logging"
)
var (
logBackend *logging.LogBackend
log *logging.Logger
debugFormat = logging.MustStringFormatter(
`%{color}%{level:.4s} %{time:15:04:05.000} %{shortfunc:.10s}: %{color:reset} %{message}`,
)
releaseFormat = logging.MustStringFormatter(
`[%{level}] - %{message}`,
)
)
func initLogging() {
log = logging.MustGetLogger("gomark")
logBackend = logging.NewLogBackend(os.Stderr, "", 0)
if IsDebugging() {
debugBackendFormatter := logging.NewBackendFormatter(logBackend, debugFormat)
logging.SetBackend(debugBackendFormatter)
} else {
backendFormatter := logging.NewBackendFormatter(logBackend, releaseFormat)
leveledBackend := logging.AddModuleLevel(backendFormatter)
leveledBackend.SetLevel(logging.WARNING, "")
logging.SetBackend(leveledBackend)
}
2017-11-19 20:42:20 +00:00
2018-10-28 19:26:38 +00:00
log.Warningf("running in %s mode", RunMode())
2017-11-19 16:00:37 +00:00
}
func IsDebugging() bool {
return gomarkMode == debugCode
}