~craftyguy/logger

f08fb0681121613ff231b9b6a2439d417dcd710a — Clayton Craft 10 months ago 2ead013
logger: use rwlock

The vast majority of the time this is reading and not setting anything,
so RLock should help in cases where there are concurrent calls to logger
methods.
1 files changed, 17 insertions(+), 17 deletions(-)

M logger.go
M logger.go => logger.go +17 -17
@@ 18,7 18,7 @@ type Logger struct {
	log     *stdLog.Logger
	filter  *logutils.LevelFilter
	noColor bool
	sync.Mutex
	sync.RWMutex
}

const (


@@ 71,50 71,50 @@ func (l *Logger) SetMinLevel(level logutils.LogLevel) {
}

func (l *Logger) Printf(f string, s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Print(format(INFO, l.noColor, fmt.Sprintf(f, s...)))
}

func (l *Logger) Println(s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Println(format(INFO, l.noColor, s...))
}

func (l *Logger) Debugf(f string, s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Print(format(DEBUG, l.noColor, fmt.Sprintf(f, s...)))
}

func (l *Logger) Debugln(s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Println(format(DEBUG, l.noColor, s...))
}

func (l *Logger) Warnf(f string, s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Print(format(WARN, l.noColor, fmt.Sprintf(f, s...)))
}

func (l *Logger) Warnln(s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Println(format(WARN, l.noColor, s...))
}

func (l *Logger) Errorf(f string, s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Print(format(ERROR, l.noColor, fmt.Sprintf(f, s...)))
}

func (l *Logger) Errorln(s ...interface{}) {
	l.Lock()
	defer l.Unlock()
	l.RLock()
	defer l.RUnlock()
	l.log.Println(format(ERROR, l.noColor, s...))
}