Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a file's mtime is not reliable when rotating log by datetime #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions writers_rollingfilewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ type rollingFileWriter struct {
fullName bool
maxRolls int
nameMode rollingNameMode
lastRollTime time.Time
self rollerVirtual // Used for virtual calls
}

Expand Down Expand Up @@ -334,9 +335,11 @@ func (rw *rollingFileWriter) createFileAndFolderIfNeeded(first bool) error {
}

rw.currentFileSize = stat.Size()
rw.lastRollTime = stat.ModTime()
} else {
rw.currentFile, err = os.Create(filePath)
rw.currentFileSize = 0
rw.lastRollTime = time.Now()
}
if err != nil {
return err
Expand Down Expand Up @@ -518,11 +521,7 @@ func (rw *rollingFileWriter) Write(bytes []byte) (n int, err error) {
// needs to roll if:
// * file roller max file size exceeded OR
// * time roller interval passed
fi, err := rw.currentFile.Stat()
if err != nil {
return 0, err
}
lastRollTime := fi.ModTime()
lastRollTime := rw.lastRollTime
nr, err := rw.self.needsToRoll(lastRollTime)
if err != nil {
return 0, err
Expand Down