fix: log currentSize should not be 0 when file exists and size is not 0 (#2639)

master
edieruby 2 years ago committed by GitHub
parent 97a8b3ade5
commit b1c3c21c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -284,7 +284,7 @@ func (l *RotateLogger) getBackupFilename() string {
func (l *RotateLogger) init() error { func (l *RotateLogger) init() error {
l.backup = l.rule.BackupFileName() l.backup = l.rule.BackupFileName()
if _, err := os.Stat(l.filename); err != nil { if fileInfo, err := os.Stat(l.filename); err != nil {
basePath := path.Dir(l.filename) basePath := path.Dir(l.filename)
if _, err = os.Stat(basePath); err != nil { if _, err = os.Stat(basePath); err != nil {
if err = os.MkdirAll(basePath, defaultDirMode); err != nil { if err = os.MkdirAll(basePath, defaultDirMode); err != nil {
@ -295,9 +295,12 @@ func (l *RotateLogger) init() error {
if l.fp, err = os.Create(l.filename); err != nil { if l.fp, err = os.Create(l.filename); err != nil {
return err return err
} }
} else if l.fp, err = os.OpenFile(l.filename, os.O_APPEND|os.O_WRONLY, defaultFileMode); err != nil { } else {
if l.fp, err = os.OpenFile(l.filename, os.O_APPEND|os.O_WRONLY, defaultFileMode); err != nil {
return err return err
} }
l.currentSize = fileInfo.Size()
}
fs.CloseOnExec(l.fp) fs.CloseOnExec(l.fp)

Loading…
Cancel
Save