mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +08:00
bug/log-file-rotate: fix big file even with rotate-by-size and rotate-back-expire
This commit is contained in:
parent
4dd12434b7
commit
edc67d9ec3
@ -229,7 +229,6 @@ func (l *Logger) printToFile(now time.Time, buffer *bytes.Buffer) {
|
||||
gmlock.Lock(memoryLockKey)
|
||||
defer gmlock.Unlock(memoryLockKey)
|
||||
file := l.getFilePointer(logFilePath)
|
||||
defer file.Close()
|
||||
// Rotation file size checks.
|
||||
if l.config.RotateSize > 0 {
|
||||
stat, err := file.Stat()
|
||||
@ -239,12 +238,13 @@ func (l *Logger) printToFile(now time.Time, buffer *bytes.Buffer) {
|
||||
if stat.Size() > l.config.RotateSize {
|
||||
l.rotateFileBySize(now)
|
||||
file = l.getFilePointer(logFilePath)
|
||||
defer file.Close()
|
||||
}
|
||||
}
|
||||
if _, err := file.Write(buffer.Bytes()); err != nil {
|
||||
defer file.Close()
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
}
|
||||
|
||||
// getFilePointer retrieves and returns a file pointer from file pool.
|
||||
|
Loading…
Reference in New Issue
Block a user