diff --git a/config/config.go b/config/config.go index 30284f021..860c66005 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,7 @@ var MemeUrl string var RelayAuthKey string var RelayNodeKey string var SuperAdmins []string = []string{""} +var LogLevel string // these are constants for the store var InvoiceList = "INVOICELIST" @@ -67,6 +68,7 @@ func InitConfig() { V2BotUrl = os.Getenv("V2_BOT_URL") V2BotToken = os.Getenv("V2_BOT_TOKEN") FfWebsocket = os.Getenv("FF_WEBSOCKET") == "true" + LogLevel = os.Getenv("LOG_LEVEL") // Add to super admins SuperAdmins = StripSuperAdmins(AdminStrings) @@ -135,6 +137,10 @@ func InitConfig() { if JarvisToken == "" { JarvisToken = "" } + + if LogLevel == "" { + LogLevel = "DEBUG" + } } func StripSuperAdmins(adminStrings string) []string { diff --git a/utils/logger.go b/utils/logger.go index 15c61b0b6..e32d9f06f 100644 --- a/utils/logger.go +++ b/utils/logger.go @@ -3,28 +3,53 @@ package utils import ( "log" "os" + "strings" ) type Logger struct { - infoLogger *log.Logger - errorLogger *log.Logger - debugLogger *log.Logger + infoLogger *log.Logger + warningLogger *log.Logger + errorLogger *log.Logger + debugLogger *log.Logger + machineLogger *log.Logger + logLevel string } var Log = Logger{ - infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), - errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), - debugLogger: log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), + infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), + warningLogger: log.New(os.Stdout, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile), + errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), + debugLogger: log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), + machineLogger: log.New(os.Stdout, "MACHINE: ", log.Ldate|log.Ltime|log.Lshortfile), + logLevel: strings.ToUpper(os.Getenv("LOG_LEVEL")), +} + +func (l *Logger) Machine(format string, v ...interface{}) { + if l.logLevel == "MACHINE" { + l.machineLogger.Printf(format, v...) + } +} + +func (l *Logger) Debug(format string, v ...interface{}) { + if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" { + l.debugLogger.Printf(format, v...) + } } func (l *Logger) Info(format string, v ...interface{}) { - l.infoLogger.Printf(format, v...) + if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" || l.logLevel == "INFO" { + l.infoLogger.Printf(format, v...) + } } -func (l *Logger) Error(format string, v ...interface{}) { - l.errorLogger.Printf(format, v...) +func (l *Logger) Warning(format string, v ...interface{}) { + if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" || l.logLevel == "INFO" || l.logLevel == "WARNING" { + l.warningLogger.Printf(format, v...) + } } -func (l *Logger) Debug(format string, v ...interface{}) { - l.debugLogger.Printf(format, v...) +func (l *Logger) Error(format string, v ...interface{}) { + if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" || l.logLevel == "INFO" || l.logLevel == "WARNING" || l.logLevel == "ERROR" { + l.errorLogger.Printf(format, v...) + } }