2
0

go back to using defer to unlock in close and rotate

This commit is contained in:
Nate Finch
2014-06-16 15:29:37 -04:00
parent ffd1aed5ff
commit 06f4f4ea5e
+4 -6
View File
@@ -141,9 +141,8 @@ func (l *Logger) Write(p []byte) (n int, err error) {
// Close implements io.Closer, and closes the current logfile. // Close implements io.Closer, and closes the current logfile.
func (l *Logger) Close() error { func (l *Logger) Close() error {
l.mu.Lock() l.mu.Lock()
err := l.close() defer l.mu.Unlock()
l.mu.Unlock() return l.close()
return err
} }
// close closes the file if it is open. // close closes the file if it is open.
@@ -163,9 +162,8 @@ func (l *Logger) close() error {
// to the normal rules. // to the normal rules.
func (l *Logger) Rotate() error { func (l *Logger) Rotate() error {
l.mu.Lock() l.mu.Lock()
err := l.rotate() defer l.mu.Unlock()
l.mu.Unlock() return l.rotate()
return err
} }
// rotate closes the current file, if any, opens a new file, and then calls // rotate closes the current file, if any, opens a new file, and then calls