hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.7k stars 502 forks source link

Read all file content and continue tailing #147

Closed stgleb closed 6 years ago

stgleb commented 6 years ago

I've got a log file that is continuously updated. I want to read the entire file content that exists at the moment and continue with tail -f of this file. Which configuration do I need to do so?

tail.Config{
            Follow:      true,
            MustExist:   true,
            Location: &tail.SeekInfo{
                Offset: 0,
                Whence: io.SeekStart,
            },
            Logger: tail.DiscardingLogger,
            MaxLineSize: 160,
        }
stgleb commented 6 years ago

Resolved

korobkovr commented 1 year ago
    t, err := tail.TailFile(logFile, tail.Config{
        Location: &tail.SeekInfo{
            Offset: 0,
            Whence: os.SEEK_END,
        },
        Follow: true,
    })
securityguy commented 1 year ago

I also set ReOpen to true. I'm not sure if that applies to your use case. Note that I'm reading log files, so I use SeekEnd as well.

tail.Config{Follow: true, ReOpen: true, Location: &tail.SeekInfo{Offset: 0, Whence: io.SeekEnd}})