Skip to content

Commit

Permalink
refactor: add GetSecondaryPrefix method
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-gang committed Jul 4, 2024
1 parent a750a92 commit cb30f31
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,22 @@ func GetLogger(isDebug bool, prefix string) *Logger {
}

func (l *Logger) UpdateSecondaryPrefix(prefix string) {
// Pass in the actual prefix that will be used.
// Else, if we want to use a series of [prefix1][prefix2] that fails
l.secondaryPrefix = prefix
if prefix == "" {
// Reset the prefix to the original one.
l.logger.SetPrefix(yellowColorize(l.prefix)[0])
} else {
// Append the secondary prefix to the original one.
l.logger.SetPrefix(yellowColorize(l.prefix + fmt.Sprintf("[%s] ", prefix))[0])
l.logger.SetPrefix(yellowColorize(l.prefix + prefix)[0])
}
}

func (l *Logger) GetSecondaryPrefix() string {
return l.secondaryPrefix
}

func (l *Logger) ResetSecondaryPrefix() {
l.UpdateSecondaryPrefix("")
}
Expand Down

0 comments on commit cb30f31

Please sign in to comment.