Skip to content

mattalxndr/bettertail

Repository files navigation

bettertail

Monitor log files in a directory and output new lines as they're appended in real-time.

Usage

bettertail DIRECTORY [GLOB]

Arguments:

  • DIRECTORY - Directory to watch for log files (required)
  • GLOB - File pattern to match (optional, default: **/*.log)

Examples:

# Watch all .log files in /var/log
bettertail /var/log

# Watch only application logs
bettertail /var/log "app-*.log"

# Watch all text files in current directory
bettertail . "**/*.txt"

Features

  • Real-time monitoring - Detects and outputs new lines as they're written
  • Pattern matching - Supports glob patterns for flexible file selection
  • Recursive watching - Monitors subdirectories automatically
  • Log rotation handling - Correctly handles truncated and rotated logs
  • Clean output - Each line shows relative path and content

Installation

pip install bettertail

Or with uv:

uv pip install bettertail

Development Guidelines

  • The script should be concerned with newly appended lines, not with files. Which means:
    • Only new lines, appended to log files should be printed.
    • If a file is moved or renamed, the existing lines in the file should not be be printed, since they are not new lines.
    • If a file is deleted, then nothing should be printed.
    • When the script is first run, it should print nothing. It should instead wait for new lines to be appended to the log files it's watching.
    • If an empty file is created in the directory, then nothing should be printed.
    • (Note: Obviously it will be helpful to see these file movements during testing, in debug/verbose mode, but normal operation is religious about lines, not files)
  • Each line should for formatted this way: "${rel path to file from root dir}: ${line content}\n".

About

Tail and follow all lines written to files in a directory.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published