# README
Tailor, the library for tailing logs under logrotate
Tailor provides the functionality of tailing for e. g. nginx logs under logrotate. Tailor will follow a selected log file and reopen it if it's been rotated. Now, tailor doesn't require inotify, because it polls logs with a tiny delay. So the library can achieve cross-platform.
There is no plan to implement truncate detection.
Currently this library is used in production, handling 5k of opened files with a load over 100k rps per instance,
without such overhead.
Install
go get github.com/un000/tailor
TODO
- Better Test Code Coverage
- Benchmarks
- Rate limiter + Leaky Bucket
Example
package main
import (
"context"
"fmt"
"io"
"time"
"github.com/un000/tailor"
)
func main() {
t := tailor.New(
"./github.com_access.log",
tailor.WithSeekOnStartup(0, io.SeekStart),
tailor.WithPollerTimeout(10*time.Millisecond),
)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err := t.Run(ctx)
if err != nil {
panic(err)
}
fmt.Println("Tailing file:", t.FileName())
for {
select {
case line, ok := <-t.Lines():
if !ok {
return
}
fmt.Println(line.StringTrimmed())
case err, ok := <-t.Errors():
if !ok {
return
}
panic(err)
}
}
}
Contributions are appreciated, feel free ✌️
# Packages
No description provided by the author
# Functions
New prepares the instance of Tailor.
NewChannelBasedRateLimiter creates an instance of rate limiter, which ticker ticks every period to limit the lps.
WithLeakyBucket is used to skip a read lines, when a listener is full.
WithPollerTimeout is used to timeout when file is fully read, to check changes.
WithRateLimiter is used to rate limit output lines.
WithReaderInitialPoolSize is used to set the internal initial size of bufio.Reader buffer.
WithSeekOnRun is used to set file.Seek() options, when the file is opened on startup.
WithSeekOnStartup is used to set file.Seek() options, when the file is opened on startup.
WithUpdateLagInterval is used to know how often update the file lag.
# Structs
No description provided by the author
Line represents a returned line from the tailed file.
No description provided by the author
# Interfaces
RateLimiter provides methods to create a custom rate limiter.
# Type aliases
No description provided by the author