Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #378 from kolyshkin/19.03-backport-log-max-file-1-…
Browse files Browse the repository at this point in the history
…follow

[19.03 backport] logger: fix follow logs for max-file=1
  • Loading branch information
thaJeztah authored Sep 24, 2019
2 parents 53b9d44 + 1e13f66 commit cf298d3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion daemon/logger/loggerutils/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func compressFile(fileName string, lastTimestamp time.Time) {
compressWriter := gzip.NewWriter(outFile)
defer compressWriter.Close()

// Add the last log entry timestramp to the gzip header
// Add the last log entry timestamp to the gzip header
extra := rotateFileMetadata{}
extra.LastTime = lastTimestamp
compressWriter.Header.Extra, err = json.Marshal(&extra)
Expand Down Expand Up @@ -614,11 +614,25 @@ func followLogs(f *os.File, logWatcher *logger.LogWatcher, notifyRotate chan int
}
}

oldSize := int64(-1)
handleDecodeErr := func(err error) error {
if errors.Cause(err) != io.EOF {
return err
}

// Handle special case (#39235): max-file=1 and file was truncated
st, stErr := f.Stat()
if stErr == nil {
size := st.Size()
defer func() { oldSize = size }()
if size < oldSize { // truncated
f.Seek(0, 0)
return nil
}
} else {
logrus.WithError(stErr).Warn("logger: stat error")
}

for {
err := waitRead()
if err == nil {
Expand Down

0 comments on commit cf298d3

Please sign in to comment.