hpcloud / tail

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

Add "tail -n" functionality #123

Open AndriiChuzhynov opened 7 years ago

AndriiChuzhynov commented 7 years ago

Hi, here is my implementation of feature request #83 It adds 4 configuration options:

  1. LastLines - outputs the last NUM lines. It's done by finding the location of required line and changing tail.Config.Location according to found location. While seeking it stepping back by bytes defined by PageSize (4096 default). It's done to avoid reading the whole file.

  2. FromLine - the same as LastLines, but looking for the line from the start.

  3. PageSize - The optional option. Configures the buffer size for step. Might be reasonable to increase if the file is huge.

  4. SeekOnReOpen - By default if a file was reopened no line seek performed. If this option configured as True - reopened file will be read with the desired line.

If LastLines and FromLine both configured FromLine will be used and LastLines will be ignored. If NUM of lines 0 or less nothing will happen. It works with "follow" and without it as well.

I'll appreciate for any comments and suggestions.

dinoba commented 7 years ago

Hi,

any update about this?

nishantroy commented 6 years ago

Came to request this feature^ Any updates @AndriiChuzhynov ?