2
0

move mutex to unexported field

This commit is contained in:
Nate Finch
2014-06-16 06:56:15 -04:00
parent cf9adaef63
commit 6412f2cf51
+7 -7
View File
@@ -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