Revert "move mutex to unexported field"
This reverts commit 86271c05bd.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
# lumberjack [](https://godoc.org/github.com/natefinch/lumberjack) [](https://travis-ci.org/natefinch/lumberjack)
|
# lumberjack [](https://godoc.org/github.com/natefinch/lumberjack)
|
||||||
|
|
||||||
|
|
||||||
|
[](https://travis-ci.org/natefinch/lumberjack)
|
||||||
|
|
||||||
### Lumberjack is a Go package for writing logs to rolling files.
|
### Lumberjack is a Go package for writing logs to rolling files.
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -110,7 +110,7 @@ type Logger struct {
|
|||||||
|
|
||||||
size int64
|
size int64
|
||||||
file *os.File
|
file *os.File
|
||||||
mu sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// currentTime is only used for testing. Normally it's the time.Now() function.
|
// 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
|
// PathFormat. If the length of the write is greater than MaxSize, an error is
|
||||||
// returned that satisfies IsWriteTooLong.
|
// returned that satisfies IsWriteTooLong.
|
||||||
func (l *Logger) Write(p []byte) (n int, err error) {
|
func (l *Logger) Write(p []byte) (n int, err error) {
|
||||||
l.mu.Lock()
|
l.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.Unlock()
|
||||||
writeLen := int64(len(p))
|
writeLen := int64(len(p))
|
||||||
if writeLen > l.max() {
|
if writeLen > l.max() {
|
||||||
return 0, fmt.Errorf(
|
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.
|
// Close implements io.Closer, and closes the current logfile.
|
||||||
func (l *Logger) Close() error {
|
func (l *Logger) Close() error {
|
||||||
l.mu.Lock()
|
l.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.Unlock()
|
||||||
if l.file != nil {
|
if l.file != nil {
|
||||||
err := l.file.Close()
|
err := l.file.Close()
|
||||||
l.file = nil
|
l.file = nil
|
||||||
@@ -176,8 +176,8 @@ func (l *Logger) Close() error {
|
|||||||
// SIGHUP. After rotating, this initiates a cleanup of old log files according
|
// SIGHUP. After rotating, this initiates a cleanup of old log files according
|
||||||
// to the normal rules.
|
// to the normal rules.
|
||||||
func (l *Logger) Rotate() error {
|
func (l *Logger) Rotate() error {
|
||||||
l.mu.Lock()
|
l.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.Unlock()
|
||||||
if l.file != nil {
|
if l.file != nil {
|
||||||
if err := l.file.Close(); err != nil {
|
if err := l.file.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user