bug/log-file-rotate: fix big file even with rotate-by-size and rotate-back-expire

This commit is contained in:
muyakongali 2020-07-17 10:39:14 +08:00
parent 4dd12434b7
commit edc67d9ec3

View File

@ -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.