From 6412f2cf5185d6c1cc720667bb3dfb5b8e2a3e33 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Mon, 16 Jun 2014 06:56:15 -0400 Subject: [PATCH] move mutex to unexported field --- lumberjack.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lumberjack.go b/lumberjack.go index f469c60..c6ca372 100644 --- a/lumberjack.go +++ b/lumberjack.go @@ -110,7 +110,7 @@ type Logger struct { size int64 file *os.File - sync.Mutex + mu sync.Mutex } // currentTime is only used for testing. Normally it's the time.Now() function. @@ -121,8 +121,8 @@ var currentTime = time.Now // PathFormat. If the length of the write is greater than MaxSize, an error is // returned that satisfies IsWriteTooLong. func (l *Logger) Write(p []byte) (n int, err error) { - l.Lock() - defer l.Unlock() + l.mu.Lock() + defer l.mu.Unlock() writeLen := int64(len(p)) if writeLen > l.max() { return 0, fmt.Errorf( @@ -160,8 +160,8 @@ func (l *Logger) Write(p []byte) (n int, err error) { // Close implements io.Closer, and closes the current logfile. func (l *Logger) Close() error { - l.Lock() - defer l.Unlock() + l.mu.Lock() + defer l.mu.Unlock() if l.file != nil { err := l.file.Close() l.file = nil @@ -176,8 +176,8 @@ func (l *Logger) Close() error { // SIGHUP. After rotating, this initiates a cleanup of old log files according // to the normal rules. func (l *Logger) Rotate() error { - l.Lock() - defer l.Unlock() + l.mu.Lock() + defer l.mu.Unlock() if l.file != nil { if err := l.file.Close(); err != nil { return err