Skip to content

Commit

Permalink
Fix rotate file
Browse files Browse the repository at this point in the history
  • Loading branch information
bamboox committed Jul 3, 2020
1 parent b5c3182 commit d2c1c11
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,19 @@ func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error {
}
var err error
sb.file, _, err = create(severityName[sb.sev], now, startup)
sb.nbytes = 0
if err != nil {
return err
}

if startup {
fileInfo, err := sb.file.Stat()
if err != nil {
return fmt.Errorf("file stat could not get fileinfo: %v", err)
}
// init file size
sb.nbytes = uint64(fileInfo.Size())
} else {
sb.nbytes = 0
}
sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)

if sb.logger.skipLogHeaders {
Expand Down

0 comments on commit d2c1c11

Please sign in to comment.