Skip to content

Commit

Permalink
Re-use logger instance (evcc-io#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboehmke authored Jun 26, 2021
1 parent 71ae0de commit 6014100
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type Logger struct {

// NewLogger creates a logger with the given log area and adds it to the registry
func NewLogger(area string) *Logger {
loggersMux.Lock()
defer loggersMux.Unlock()

if logger, ok := loggers[area]; ok {
return logger
}

padded := area
for len(padded) < LogAreaPadding {
padded = padded + " "
Expand All @@ -44,9 +51,6 @@ func NewLogger(area string) *Logger {
level := LogLevelForArea(area)
notepad := jww.NewNotepad(level, level, os.Stdout, io.Discard, padded, log.Ldate|log.Ltime)

loggersMux.Lock()
defer loggersMux.Unlock()

logger := &Logger{
Notepad: notepad,
name: area,
Expand Down

0 comments on commit 6014100

Please sign in to comment.