Skip to content

Commit

Permalink
chore: Refactor logger to remove unused log levels and enable test lo…
Browse files Browse the repository at this point in the history
…g visibility
  • Loading branch information
zomasec committed Jul 28, 2024
1 parent 9ca5dd3 commit 3a8f6a1
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ type Logger interface {
// LoggerOptions struct represents the default logger implementation.
type LoggerOptions struct {
Formatter Formatter
ColorEnabled bool // Controls color output
DebugEnabled bool // Controls debug log visibility
InfoEnabled bool // Controls info log visibility
WarningEnabled bool // Controls warning log visibility
ErrorEnabled bool // Controls error log visibility
FatalEnabled bool // Controls fatal log visibility
TestEnabled bool // Controls test log visibility

}

var (
Expand All @@ -41,41 +35,28 @@ func Msg() Logger {
once.Do(func() {
instance = &LoggerOptions{
Formatter: Formatter{},
ColorEnabled: true, // Colors are enabled by default
DebugEnabled: true, // All log levels are visible by default
InfoEnabled: true, // All log levels are visible by default
WarningEnabled: true, // All log levels are visible by default
ErrorEnabled: true, // All log levels are visible by default
FatalEnabled: true, // All log levels are visible by default
TestEnabled: true, // All log levels are visible by default

}
})
return instance
}

func (l *LoggerOptions) colorize(holder, color string) {
if l.ColorEnabled {
l.Formatter.SetHolder(fmt.Sprintf("%s%s%s", color, holder, Colors[Reset]))
} else {
l.Formatter.SetHolder(holder)
}

l.Formatter.SetHolder(fmt.Sprintf("%s%s%s", color, holder, Colors[Reset]))

}

// Info logs an info message with the specified message and arguments.
func (l *LoggerOptions) Info(msg string, args ...interface{}) {
if !l.InfoEnabled {
return
}

l.colorize(Info.String(), Colors[Blue])
l.Formatter.SetMessage(msg, args...)
l.Formatter.Log()
}

// Debug logs a debug message with the specified message and arguments.
func (l *LoggerOptions) Debug(msg string, args ...interface{}) {
if !l.DebugEnabled {
return
}
func (l *LoggerOptions) Debug(msg string, args ...interface{}) {

l.colorize(Debug.String(), Colors[Purple])
l.Formatter.SetMessage(msg, args...)
Expand All @@ -84,38 +65,30 @@ func (l *LoggerOptions) Debug(msg string, args ...interface{}) {

// Warn logs a warning message with the specified message and arguments.
func (l *LoggerOptions) Warn(msg string, args ...interface{}) {
if !l.WarningEnabled {
return
}

l.colorize(Warn.String(), Colors[Yellow])
l.Formatter.SetMessage(msg, args...)
l.Formatter.Log()
}

// Error logs an error message with the specified message and arguments.
func (l *LoggerOptions) Error(msg string, args ...interface{}) {
if !l.ErrorEnabled {
return
}

l.colorize(Error.String(), Colors[Red])
l.Formatter.SetMessage(msg, args...)
l.Formatter.Log()
}

// Fatal logs a fatal message with the specified message and arguments.
func (l *LoggerOptions) Fatal(msg string, args ...interface{}) {
if !l.FatalEnabled {
return
}

l.colorize(Fatal.String(), Colors[Orange])
l.Formatter.SetMessage(msg, args...)
l.Formatter.Log()
}

func (l *LoggerOptions) Test(msg string, args ...interface{}) {
if !l.DebugEnabled {
return
}

l.colorize(Test.String(), Colors[Green])
l.Formatter.SetMessage(msg, args...)
l.Formatter.Log()
Expand Down

0 comments on commit 3a8f6a1

Please sign in to comment.