Skip to content

mariusvniekerk/tailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tailer

tailer is a CLI for watching a directory of log files by pattern.

It behaves like tail -f, but it also keeps rescanning the directory and starts following new matching files as they appear. This is useful for log directories where new files are dropped over time.

Install

Build and install from this repository:

go install ./cmd/tailer

Install a tagged release directly:

go install github.com/mariusvniekerk/tailer/cmd/tailer@latest

The binary will be installed to GOBIN if it is set. Otherwise Go installs it to $(go env GOPATH)/bin.

For example:

$(go env GOPATH)/bin/tailer

Usage

tailer --dir <directory> --pattern <glob>

Example:

tailer --dir /var/log/myapp --pattern "*.log"

This will:

  • Find existing files in /var/log/myapp matching *.log
  • Start following appended lines in those files
  • Detect new *.log files in that directory
  • Start following those new files automatically
  • Prefix each output line with the source file path

Flags

-dir string
    Directory to watch for matching files. (default ".")
-from-start
    Start existing files from byte 0 instead of the end.
-pattern string
    Glob pattern for files inside the watched directory. (default "*.log")
-poll-interval duration
    How often to rescan the directory for new files. (default 1s)

Output Format

Each emitted line is prefixed with the full path of the source file:

/var/log/myapp/app.log: request complete
/var/log/myapp/worker.log: job queued

Common Examples

Tail all log files in the current directory:

tailer --pattern "*.log"

Read existing files from the beginning instead of starting at EOF:

tailer --dir ./logs --pattern "*.log" --from-start

Use faster directory rescans for rapidly created files:

tailer --dir ./logs --pattern "*.log" --poll-interval 250ms

Watch rotated or recreated files:

tailer --dir ./logs --pattern "app-*.log"

tailer uses github.com/nxadm/tail for low-level tail-follow behavior, including reopen support.

The CLI itself is built with Cobra.

Current Scope

The current implementation:

  • Watches one directory, not recursive subdirectories
  • Uses glob matching against filenames in that directory
  • Starts existing files at EOF by default
  • Starts newly discovered files from the beginning
  • Stops cleanly on Ctrl-C

Development

Run tests:

go test ./...

Build the binary:

go build ./...

About

CLI to tail matching files in a directory and auto-follow new ones

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors