Merge pull request #39969 from kolyshkin/log-max-file-1-follow
logger: fix follow logs for max-file=1
This commit is contained in:
commit
a36dfe758d
|
@ -265,7 +265,7 @@ func compressFile(fileName string, lastTimestamp time.Time) {
|
||||||
compressWriter := gzip.NewWriter(outFile)
|
compressWriter := gzip.NewWriter(outFile)
|
||||||
defer compressWriter.Close()
|
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 := rotateFileMetadata{}
|
||||||
extra.LastTime = lastTimestamp
|
extra.LastTime = lastTimestamp
|
||||||
compressWriter.Header.Extra, err = json.Marshal(&extra)
|
compressWriter.Header.Extra, err = json.Marshal(&extra)
|
||||||
|
@ -614,11 +614,25 @@ func followLogs(f *os.File, logWatcher *logger.LogWatcher, notifyRotate chan int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldSize := int64(-1)
|
||||||
handleDecodeErr := func(err error) error {
|
handleDecodeErr := func(err error) error {
|
||||||
if errors.Cause(err) != io.EOF {
|
if errors.Cause(err) != io.EOF {
|
||||||
return err
|
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 {
|
for {
|
||||||
err := waitRead()
|
err := waitRead()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in New Issue