https://github.com/gaols/tail
go package for tailing file, just like 'tail -f'
https://github.com/gaols/tail
golang-tail tail tail-f tail-file tailf
Last synced: 6 months ago
JSON representation
go package for tailing file, just like 'tail -f'
- Host: GitHub
- URL: https://github.com/gaols/tail
- Owner: gaols
- License: mit
- Created: 2021-11-25T05:26:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-30T22:43:57.000Z (over 4 years ago)
- Last Synced: 2025-08-09T21:38:20.102Z (11 months ago)
- Topics: golang-tail, tail, tail-f, tail-file, tailf
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tail
Tail a file programmatically just like you run shell command `tail -f /somefile`.
## Features
* support tail a non-exist file until that file exists
* tail works even if file get removed or truncated
* tail from specified offset
## Basic usage
```
// closeFunc is used to stop tailing
lineCh, closeFunc, errCh := tail.TailF("/path/to/file", true)
go func() {
for {
select {
case <-errCh:
return
case line := <-lineCh:
fmt.Println(line)
}
}
}()
```
## Advance usage
by default, tail poll file delete/truncate-event every 10 seconds, you can
config poll interval to satisfy your own needs.
```
lineCh, closeFunc, errCh := tail.TailWithConfig("/path/to/file", true, &tail.Config{PollInterval: 500 * time.Millisecond})
go func() {
for {
select {
case <-errCh:
return
case line := <-lineCh:
fmt.Println(line)
}
}
}()
```
## More configs
### config tail offset
```
// tail.SeekFromStart/tail.SeekFromEnd/tail.SeekOffsetAuto
lineCh, closeFunc, errCh := tail.TailWithConfig("/path/to/file", true, &tail.Config{
PollInterval: 500 * time.Millisecond,
Offset: tail.SeekFromStart,
})
```
## Limitations
Not tested on windows.