package main import ( "io" "os" log "github.com/sirupsen/logrus" prefixed "github.com/x-cray/logrus-prefixed-formatter" ) func NewLog() *log.Logger { if Cfg.General.DeleteLogFileAtStart { if _, err := os.Stat("flexradio.log"); err == nil { os.Remove("flexradio.log") } } var w io.Writer if Cfg.General.LogToFile { f, err := os.OpenFile("flexradio.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { panic(err) } w = io.MultiWriter(os.Stdout, f) } else { w = io.Writer(os.Stdout) } l := &log.Logger{ Out: w, Formatter: &prefixed.TextFormatter{ DisableColors: false, TimestampFormat: "02-01-2006 15:04:05", FullTimestamp: true, ForceFormatting: true, }, } if Cfg.General.LogLevel == "DEBUG" { l.Level = log.DebugLevel } else if Cfg.General.LogLevel == "INFO" { l.Level = log.InfoLevel } else if Cfg.General.LogLevel == "WARN" { l.Level = log.WarnLevel } else { l.Level = log.InfoLevel } return l } // Info ... func Info(format string, v ...interface{}) { log.Infof(format, v...) } // Warn ... func Warn(format string, v ...interface{}) { log.Warnf(format, v...) } // Error ... func Error(format string, v ...interface{}) { log.Errorf(format, v...) } func Debug(format string, v ...interface{}) { log.Debugf(format, v...) }