stating an existing file only once

This commit is contained in:
Diptanu Choudhury 2016-01-16 20:09:24 -08:00
parent 4122aeedc8
commit d3734a47cd

View file

@ -65,21 +65,19 @@ func (l *LogRotator) Start(r io.Reader) error {
buf := make([]byte, bufSize)
for {
logFileName := filepath.Join(l.path, fmt.Sprintf("%s.%d", l.fileName, l.logFileIdx))
remainingSize := l.fileSize
if f, err := os.Stat(logFileName); err == nil {
if f.IsDir() {
l.logFileIdx += 1
continue
}
remainingSize = l.fileSize - f.Size()
}
f, err := os.OpenFile(logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return err
}
l.logger.Println("[INFO] logrotator: opened a new file: %s", logFileName)
remainingSize := l.fileSize
if finfo, err := os.Stat(logFileName); err == nil {
remainingSize -= finfo.Size()
}
if remainingSize < 1 {
l.logFileIdx = l.logFileIdx + 1
f.Close()