Skip to content

Commit

Permalink
feat: introduce a levelStr to logger
Browse files Browse the repository at this point in the history
Signed-off-by: mlycore <[email protected]>
  • Loading branch information
mlycore committed Mar 8, 2024
1 parent 38fde31 commit e93bcac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func NewLogger(writer io.Writer, level, caller int) *Logger {
logger = &Logger{
Writer: writer,
Level: level,
LevelStr: getLogLevel(level),
CallPath: caller,
formatter: &TextFormatter{},
}
Expand Down
9 changes: 6 additions & 3 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type Logger struct {
formatter Formatter
entries sync.Pool

Level int
Level int
// TODO: remove this later
LevelStr string
CallPath int
Async bool
// Sink Sink
Expand Down Expand Up @@ -72,6 +74,7 @@ func (l *Logger) SetLevel(level int) {
l.mu.Lock()
defer l.mu.Unlock()
l.Level = level
l.LevelStr = getLogLevel(level)
}

// SetLevelByName set the log level by name
Expand Down Expand Up @@ -112,10 +115,10 @@ func (l *Logger) doPrint(level int, ctx Context, format string, v ...interface{}
fmt.Fprintln(l.Writer, msg)
}

func (l *Logger) doPrintln(level int, ctx Context, format string, msg string) {
func (l *Logger) doPrintln(ctx Context, format string, msg string) {
fields := &Fields{
Timestamp: getTimestamp(),
Level: getLogLevel(level),
Level: l.LevelStr,
Msg: msg,
}

Expand Down

0 comments on commit e93bcac

Please sign in to comment.