Skip to content

Commit

Permalink
logs: Seek the file only if it is large enough
Browse files Browse the repository at this point in the history
  • Loading branch information
unkaktus committed Jun 3, 2024
1 parent f86e0d8 commit f243eef
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,27 @@ func Logtail(b BatchSystem, jobName, outputType string, nBytes int) error {
logFile = job.ErrorFile
}

location := &tail.SeekInfo{
Offset: 0,
Whence: io.SeekStart,
}

// If the file exists and it is large enough, truncate by seeking
if fi, err := os.Stat(logFile); err == nil {
if fi.Size() > int64(nBytes) {
location = &tail.SeekInfo{
Offset: -int64(nBytes),
Whence: io.SeekEnd,
}
}
}

tailConfig := tail.Config{
Follow: true,
ReOpen: true,
Poll: true, // On many cluster filesystems, inotify doesn't work
Location: &tail.SeekInfo{
Offset: -int64(nBytes),
Whence: io.SeekEnd,
},
Logger: tail.DiscardingLogger,
Follow: true,
ReOpen: true,
Poll: true, // On many cluster filesystems, inotify doesn't work
Location: location,
Logger: tail.DiscardingLogger,
}

consoleWriter := zerolog.ConsoleWriter{
Expand Down

0 comments on commit f243eef

Please sign in to comment.