Skip to content

Commit

Permalink
fix: logger to print by config val
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed Dec 22, 2024
1 parent 8969849 commit 267a117
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +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")
LogLevel = strings.ToUpper(os.Getenv("LOG_LEVEL"))

// Add to super admins
SuperAdmins = StripSuperAdmins(AdminStrings)
Expand Down
14 changes: 7 additions & 7 deletions utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"
"os"
"strings"

"github.com/stakwork/sphinx-tribes/config"
)

type Logger struct {
Expand All @@ -12,7 +14,6 @@ type Logger struct {
errorLogger *log.Logger
debugLogger *log.Logger
machineLogger *log.Logger
logLevel string
}

var Log = Logger{
Expand All @@ -21,35 +22,34 @@ var Log = Logger{
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" {
if config.LogLevel == "MACHINE" {
l.machineLogger.Printf(format, v...)
}
}

func (l *Logger) Debug(format string, v ...interface{}) {
if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" {
if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" {
l.debugLogger.Printf(format, v...)
}
}

func (l *Logger) Info(format string, v ...interface{}) {
if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" || l.logLevel == "INFO" {
if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" {
l.infoLogger.Printf(format, v...)
}
}

func (l *Logger) Warning(format string, v ...interface{}) {
if l.logLevel == "MACHINE" || l.logLevel == "DEBUG" || l.logLevel == "INFO" || l.logLevel == "WARNING" {
if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" {
l.warningLogger.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" {
if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" || config.LogLevel == "ERROR" {
l.errorLogger.Printf(format, v...)
}
}

0 comments on commit 267a117

Please sign in to comment.