package logger import ( "os" "github.com/davecgh/go-spew/spew" "github.com/op/go-logging" ) // Log is global logger var Log = logging.MustGetLogger("myLogger") var logBackendLeveled logging.LeveledBackend // SetLogLevel sets log level for global logger (debug, info, notice, warning, error) func SetLogLevel(level string) { logBackendLevel := logging.NOTICE switch level { case "debug": logBackendLevel = logging.DEBUG break case "info": logBackendLevel = logging.INFO break case "notice": logBackendLevel = logging.NOTICE break case "warning": logBackendLevel = logging.WARNING break case "error": logBackendLevel = logging.ERROR break } logBackendLeveled.SetLevel(logBackendLevel, "") } // configureLogger sets logger backend and level func configureLogger() { logBackend := logging.NewLogBackend(os.Stderr, "", 0) logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.MustStringFormatter( `%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, )) logBackendLeveled = logging.AddModuleLevel(logBackendFormatter) logBackendLeveled.SetLevel(logging.NOTICE, "") logging.SetBackend(logBackendLeveled) } func init() { spew.Config.DisablePointerAddresses = true spew.Config.DisableCapacities = true spew.Config.DisableMethods = true spew.Config.DisablePointerMethods = true configureLogger() }