Only attempt rotation if files already exist when a Write is requested. (#18262)

This commit is contained in:
Peter Wilson 2022-12-07 15:47:43 +00:00 committed by GitHub
parent 075fdbae95
commit f80e788129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,14 +48,13 @@ type LogFile struct {
func (l *LogFile) Write(b []byte) (n int, err error) {
l.acquire.Lock()
defer l.acquire.Unlock()
// Create a new file if we have no file to write to
if l.fileInfo == nil {
if err := l.openNew(); err != nil {
return 0, err
}
}
// Check for the last contact and rotate if necessary
if err := l.rotate(); err != nil {
} else if err := l.rotate(); err != nil { // Check for the last contact and rotate if necessary
return 0, err
}