mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +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)
|
gmlock.Lock(memoryLockKey)
|
||||||
defer gmlock.Unlock(memoryLockKey)
|
defer gmlock.Unlock(memoryLockKey)
|
||||||
file := l.getFilePointer(logFilePath)
|
file := l.getFilePointer(logFilePath)
|
||||||
defer file.Close()
|
|
||||||
// Rotation file size checks.
|
// Rotation file size checks.
|
||||||
if l.config.RotateSize > 0 {
|
if l.config.RotateSize > 0 {
|
||||||
stat, err := file.Stat()
|
stat, err := file.Stat()
|
||||||
@ -239,12 +238,13 @@ func (l *Logger) printToFile(now time.Time, buffer *bytes.Buffer) {
|
|||||||
if stat.Size() > l.config.RotateSize {
|
if stat.Size() > l.config.RotateSize {
|
||||||
l.rotateFileBySize(now)
|
l.rotateFileBySize(now)
|
||||||
file = l.getFilePointer(logFilePath)
|
file = l.getFilePointer(logFilePath)
|
||||||
defer file.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := file.Write(buffer.Bytes()); err != nil {
|
if _, err := file.Write(buffer.Bytes()); err != nil {
|
||||||
|
defer file.Close()
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFilePointer retrieves and returns a file pointer from file pool.
|
// getFilePointer retrieves and returns a file pointer from file pool.
|
||||||
|
Loading…
Reference in New Issue
Block a user