package helper import ( "os" "github.com/davecgh/go-spew/spew" "github.com/op/go-logging" ) // Log is global logger var Log = logging.MustGetLogger("myLogger") // ConfigureLogger sets logger backend and level func ConfigureLogger(level string) { 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) logBackendLevel := logging.INFO 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, "") logging.SetBackend(logBackendLeveled) } func init() { spew.Config.DisablePointerAddresses = true spew.Config.DisableCapacities = true spew.Config.DisableMethods = true spew.Config.DisablePointerMethods = true }