Skip to content

Repository files navigation

ttail

A TUI for viewing and filtering log files using matching rules.

Features

  • View one or more files side by side (each file gets a header and line list; Tab moves focus between files and the rules pane)
  • Optional follow (tail) mode; use -F to follow by name (reopen on log rotation)
  • Filter lines with regex-based matching rules
  • Colour rules via JSON config (e.g. highlight ERROR, WARN, INFO)
  • Search (/), navigate, reload (r), and save filtered content
  • Load older lines from the file without a full reload: extend the initial “last N lines” window toward the start of the file (see Load older lines)
  • Configurable initial line count (-n), max lines in memory (--max-lines), rollover at list edges, and default search case sensitivity (see Configuration)
  • Optional full mode to navigate the whole file without loading everything into memory
  • Optional head mode to show the first N lines instead of the last

Build

go build -o ttail .

Configuration

Default values for many flags are read from a JSON config file. If the file does not exist, it is created on first run with built-in defaults and a message is printed to stderr:

Default config generated in /home/you/.config/ttail/ttail.json

Config file location

OSPath
Linux$XDG_CONFIG_HOME/ttail/ttail.json or ~/.config/ttail/ttail.json
Windows%APPDATA%\ttail\ttail.json
macOS~/Library/Application Support/ttail/ttail.json

Only options that make sense as persistent defaults are stored in config. One-shot options (per run) are not in config and use flag defaults only: --bytes / -c, -n +N (from line N), --full, --head, --retry, --zero-terminated / -z.

Example ttail.json

{
"num_lines": 10,
"max_lines": 1000,
"rules_file": "",
"colour_file": "",
"log_file": "",
"follow": false,
"follow_name": false,
"rollover": "both",
"searchcase": false
}
FieldMeaning
num_linesDefault for -n / --num-lines (last N lines, or first N with --head)
max_linesDefault for --max-lines (cap on lines kept in memory)
rules_fileDefault path for --rules-file
colour_fileDefault path for --colour-file
log_fileDefault for --log-file
followDefault for -f / --follow
follow_nameDefault for -F / --follow-name
rolloverDefault list wrap: "none", "start", "end", or "both" (wrap at top, bottom, or both)
searchcaseDefault: if true, search is case-sensitive; if false, case-insensitive

Command-line flags override config file values.

With --follow / -f the file is followed by descriptor (like GNU tail -f). With --follow-name / -F the file is followed by name (like GNU tail -F): if the file is replaced (e.g. by log rotation), ttail reopens it and continues following the same path. Passing -F implies -f. The defaults shown in the Flags table below are the built-in defaults when no config file exists.

Colour rule file (--colour-file)

The colour file is a JSON file that defines how to highlight parts of each line in the viewer. Pass its path via the main config (colour_file) or the --colour-file flag.

The file must contain a top-level array color_rules. Each element is an object with:

FieldMeaning
patternRegular expression. Every match in the line is highlighted with the rule’s color.
colortview color tag applied to matches, e.g. [red], [green], [yellow], [blue]. Use [-] to reset (normally added automatically after each match).
labelShort description of the rule (for reference).
rule_idUnique identifier for the rule (for reference).

Rules are applied in order. Each match is wrapped with the rule’s color and a reset, so overlapping patterns will show the colour of the rule that is applied last.

Example colour rule file

{
"color_rules": [
{ "pattern": "ERROR", "color": "[red]", "label": "Error Messages", "rule_id": "error-matcher" },
{ "pattern": "WARN", "color": "[yellow]", "label": "Warning Messages", "rule_id": "warn-matcher" },
{ "pattern": "INFO", "color": "[green]", "label": "Info Messages", "rule_id": "info-matcher" },
{ "pattern": "DEBUG", "color": "[blue]", "label": "Debug Messages", "rule_id": "debug-matcher" }
]
}

Here, any occurrence of ERROR, WARN, INFO, or DEBUG in a line is highlighted in the corresponding colour. You can use full regular expressions in pattern, e.g. \d{4}-\d{2}-\d{2} to colour ISO dates. A full example is included as colour_rule_example.json.

Usage

ttail [FILE]... [flags]

Arguments

ArgumentDescription
FILEOne or more paths to view (required). Each file is shown in its own pane with a path header and scrollable line list.

Flags

Flags that match GNU tail have a short form in parentheses.

FlagShortDescription
--num-lines-nLines: N = last N lines, +N = from line N to end (same as GNU tail -n; default: 10)
--max-linesMaximum number of lines to keep in memory (default: 1000)
--bytes-cBytes: N = last N bytes, +N = from byte N to end (same as GNU tail -c)
--rules-fileJSON file with matching rules to load at startup
--colour-fileJSON file for color rules and settings
--fullLoad and navigate the full file without loading all lines into memory
--headShow the first N lines instead of the last N
--log-filePath or directory for application logs
--follow-fFollow (tail) the file and show new lines as they are written (default: off)
--follow-name-FFollow by name: reopen when the file is replaced (e.g. log rotate); implies -f
--retryKeep trying to open the file when it is unavailable (e.g. not yet created)
--pidWith -f, exit when the process with the given PID dies (GNU tail --pid; Unix)
--sleep-intervalWith -f, poll file every N seconds (e.g. network FS); 0 = default (GNU tail -s)
--zero-terminated-zInput is NUL-delimited (GNU tail -z)
--helpShow help
--versionShow version

Keyboard shortcuts (TUI)

Press h or ? in the app for the in-TUI help popup. Summary:

Global

KeyAction
qQuit
h, ?Help
Tab / Shift+TabCycle focus between file list(s) and the rules pane
rReload output from disk (same scope as startup; not while following -f or in --full)
oCycle rollover mode (how the line list wraps at the first/last line)

Messages / file view (when focus is on a file’s line list)

KeyAction
/ Move selection
Enter, vView full selected line
fToggle follow mode (-f)
/Open search
nJump to next search match
cToggle search case sensitivity (when not in the rules pane for rule-specific c)
lLoad 10 more older lines from the file (see Load older lines)
LPrompt for how many older lines to load

Rules pane

KeyAction
dDelete selected rule
cToggle case sensitivity for the selected rule
pToggle partial match for the selected rule
aAdd matching rule (popup)
sSave (export)

Popups (search, add rule, load-older amount, help, view line)

KeyAction
EnterConfirm
EscClose

Load older lines

In the default last N lines mode (not --head, not -c, not -n +N, not --full), you can extend the window backward toward the start of the file:

  • l — append 10 older lines at the top of the buffer; the selection stays on the same logical line (the view shifts).
  • L — open a popup to type a positive number of extra older lines, then Enter to apply.

When it is unavailable:--full, follow (-f), --head, byte mode (-c), or from-line mode (-n +N). In those cases the app shows a short status message instead.

Limit: The total number of lines cannot exceed --max-lines. If you are already at the cap, you will see a message to that effect.

Multiple files: Load-older applies to the focused file pane (use Tab to switch).

Examples

ttail /var/log/app.log
ttail /var/log/a.log /var/log/b.log # two files side by side
ttail /var/log/app.log -n 100 --colour-file colour_rule_example.json
ttail /var/log/app.log -n +100 # from line 100 to end (like GNU tail -n +100)
ttail /var/log/app.log -c 1024 # last 1024 bytes
ttail /var/log/app.log -c +100 # from byte 100 to end
ttail /var/log/app.log -f --pid 1234 # follow and exit when process 1234 dies
ttail /var/log/app.log -f --sleep-interval 2 # follow, poll every 2 seconds
ttail /var/log/app.log -z file.nul # NUL-delimited input
ttail /var/log/app.log --rules-file rules.json --full

License

See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages