diff --git a/cmd/gotail/gotail.go b/cmd/gotail/gotail.go index 250af2a..99e6e97 100644 --- a/cmd/gotail/gotail.go +++ b/cmd/gotail/gotail.go @@ -11,7 +11,7 @@ import ( func args2config() tail.Config { config := tail.Config{Follow: true} - flag.IntVar(&config.Location, "n", 0, "tail from the last Nth location") + flag.Int64Var(&config.Location, "n", 0, "tail from the last Nth location") flag.BoolVar(&config.Follow, "f", false, "wait for additional data to be appended to the file") flag.BoolVar(&config.ReOpen, "F", false, "follow, and track file rename/rotation") flag.BoolVar(&config.Poll, "p", false, "use polling, instead of inotify") diff --git a/tail.go b/tail.go index 7c97ba5..29cd4ce 100644 --- a/tail.go +++ b/tail.go @@ -26,7 +26,7 @@ type Line struct { // Config is used to specify how a file must be tailed. type Config struct { - Location int // Tail from last N lines (tail -n) + Location int64 // Tail from last N lines (tail -n) Follow bool // Continue looking for new lines (tail -f) ReOpen bool // Reopen recreated files (tail -F) MustExist bool // Fail early if the file does not exist @@ -55,10 +55,6 @@ type Tail struct { // invoke the `Wait` or `Err` method after finishing reading from the // `Lines` channel. func TailFile(filename string, config Config) (*Tail, error) { - if !(config.Location == 0 || config.Location == -1) { - panic("only 0/-1 values are supported for Location.") - } - if config.ReOpen && !config.Follow { panic("cannot set ReOpen without Follow.") } @@ -143,8 +139,9 @@ func (tail *Tail) tailFileSync() { } // Seek to requested location on first open of the file. - if tail.Location == 0 { - _, err := tail.file.Seek(0, 2) // Seek to the file end + if tail.Location >= 0 { + // Seek relative to file end + _, err := tail.file.Seek(tail.Location, 2) if err != nil { tail.Killf("Seek error on %s: %s", tail.Filename, err) return