app tailspin

A log file highlighter

18 stable releases

3.0.2 Aug 17, 2024
3.0.1 Apr 1, 2024
3.0.0 Jan 21, 2024
2.4.0 Jan 11, 2024
1.3.0 Jul 31, 2023

#158 in HTTP server

Download history 77/week @ 2024-06-17 40/week @ 2024-06-24 22/week @ 2024-07-01 141/week @ 2024-07-08 79/week @ 2024-07-15 61/week @ 2024-07-22 49/week @ 2024-07-29 25/week @ 2024-08-05 198/week @ 2024-08-12 190/week @ 2024-08-19 140/week @ 2024-08-26 112/week @ 2024-09-02 95/week @ 2024-09-09 93/week @ 2024-09-16 127/week @ 2024-09-23 160/week @ 2024-09-30

486 downloads per month

MIT license

4MB
3K SLoC

A log file highlighter

Features

  • 🪵 View (or tail) any log file of any format
  • 🍰 No setup or config required
  • 🌈 Highlights numbers, dates, IP-addresses, UUIDs, URLs and more
  • ⚙️ All highlight groups are customizable
  • 🧬 Easy to integrate with other commands
  • 🔍 Uses less under the hood for scrollback, search and filtering

Table of Contents


Overview

tailspin works by reading through a log file line by line, running a series of regexes against each line. The regexes recognize patterns you expect to find in a logfile, like dates, numbers, severity keywords and more.

tailspin does not make any assumptions on the format or position of the items it wants to highlight. For this reason, it requires no configuration and the highlighting will work consistently across different logfiles.

Usage

The binary name for tailspin is tspin.

# Read from file and view in `less`
tspin application.log

# Read from file and print to stdout
tspin application.log --print

# Read from stdin and print to stdout
echo "2021-01-01 12:00:00 [INFO] This is a log message" | tspin 

# Read from another command and print to stdout
kubectl logs [pod name] --follow | tspin

Installing

Package Managers

# Homebrew
brew install tailspin

# Cargo
cargo install tailspin

# Archlinux
pacman -S tailspin

# Nix
nix-shell -p tailspin

# NetBSD
pkgin install tailspin

# FreeBSD
pkg install tailspin

From Source

cargo install --path .

Binary will be placed in ~/.cargo/bin, make sure you add the folder to your PATH environment variable.

[!IMPORTANT] When building from source, make sure that you are using the latest version of less.

Highlight Groups

Dates

Keywords

URLs

Numbers

IP Addresses

Quotes

Unix file paths

HTTP methods

UUIDs

Key-value pairs

Pointer addresses

Unix processes

Watching folders

tailspin can listen for newline entries in a given folder. Watching folders is useful for monitoring log files that are rotated.

When watching folders, tailspin will start in follow mode (abort with Ctrl + C) and will only print newline entries which arrive after the initial start.

Customizing Highlight Groups

Overview

Create config.toml in ~/.config/tailspin to customize highlight groups.

Styles have the following shape:

style = { fg = "color", bg = "color", italic = false, bold = false, underline = false }

To edit the different highlight groups, include them in your config.toml file. For example, to edit the date highlight group, add the following to your config.toml:

[date]
style = { fg = "green" }

Expand the section below to see the default config for the highlight groups:

Default highlight groups settings
[date]
number = { fg = "magenta" }
separator = { faint = true }

[date_word] # e.g. "Jan 01", "Mon Feb 28"
day = { fg = "magenta" }
month = { fg = "magenta" }
number = { fg = "magenta" }

[time]
time = { fg = "blue" }
zone = { fg = "red" }
separator = { faint = true }

[[keywords]]
words = ['null', 'true', 'false']
style = { fg = "red", italic = true }

[[keywords]]
words = ['GET']
style = { fg = "black", bg = "green" }
border = true

[url]
http = { fg = "red", faint = true }
https = { fg = "green", faint = true }
host = { fg = "blue", faint = true }
path = { fg = "blue" }
query_params_key = { fg = "magenta" }
query_params_value = { fg = "cyan" }
symbols = { fg = "red" }

[number]
style = { fg = "cyan" }

[ip]
number = { fg = "blue", italic = true }
letter = { fg = "magenta", italic = true }
separator = { fg = "red" }

[quotes]
style = { fg = "yellow" }
token = '"'

[path]
segment = { fg = "green", italic = true }
separator = { fg = "yellow" }

[uuid]
number = { fg = "blue", italic = true }
letter = { fg = "magenta", italic = true }
separator = { fg = "red" }

[pointer]
number = { fg = "blue", italic = true }
letter = { fg = "magenta", italic = true }
separator = { fg = "red" }

[key_value]
key = { faint = true }
separator = { fg = "white" }

[process]
name = { fg = "green" }
separator = { fg = "red" }
id = { fg = "yellow" }

Disabling Highlight Groups

To disable a highlight group, set the disabled field for that group to true:

[date]
disabled = true

Adding Keywords via config.toml

To add custom keywords, either include them in the list of keywords or add new entries:

[[keywords]]
words = ['MyCustomKeyword']
style = { fg = "green" }

[[keywords]]
words = ['null', 'true', 'false']
style = { fg = "red", italic = true }

Adding Keywords from the command line

Sometimes it is more convenient to add highlight groups on the fly without having to edit a TOML. To add highlights from the command line, use the --words-[red|green|yellow|blue|magenta|cyan] flag followed by a comma separated list of words to be highlighted.

Custom regex highlighters

When you need more control over the highlighting, you can use the regex highlighter. This highlighter allows you to specify a regex and a style to be applied to the matched text.

It supports one capture group (). When found, it will apply the style to the captured text.

[[regexps]]
regular_expression = 'Started (.*)\.'
style = { fg = "red" }

Working with stdin and stdout

By default, tailspin will open a file in the pager less. However, if you pipe something into tailspin, it will print the highlighted output directly to stdout. This is similar to running tspin [file] --print.

To let tailspin highlight the logs of different commands, you can pipe the output of those commands into tailspin like so:

journalctl -f | tspin
cat /var/log/syslog | tspin
kubectl logs -f pod_name | tspin

Using the pager less

Overview

tailspin uses less as its pager to view the highlighted log files. You can get more info on less via the man command (man less) or by hitting the h button to access the help screen.

Navigating

Navigating within less uses a set of keybindings that may be familiar to users of vim or other vi-like editors. Here's a brief overview of the most useful navigation commands:

  • j/k: Scroll one line up / down
  • d/u: Scroll one half-page up / down
  • g/G: Go to the top / bottom of the file

Follow mode

When you run tailspin with the -f or --follow flag, it will scroll to the bottom and print new lines to the screen as they're added to the file.

To stop following the file, interrupt with Ctrl + C. This will stop the tailing, but keep the file open, allowing you to review the existing content.

To resume following the file from within less, press Shift + F.

Use / followed by your search query. For example, /ERROR finds the first occurrence of ERROR.

After the search, n finds the next instance, and N finds the previous instance.

Filtering

less allows filtering lines by a keyword, using & followed by the pattern. For instance, &ERROR shows only lines with ERROR.

To only show lines containing either ERROR or WARN, use a regular expression: &\(ERROR\|WARN\).

To clear the filter, use & with no pattern.

Settings

-f, --follow                     Follow the contents of the file
-e, --start-at-end               Start at the end of the file
-p, --print                      Print the output to stdout
-c, --listen-command [CMD]       Listen the output (stdout) of the provided command
    --config-path [PATH]         Use the configuration file from the provided path
    --words-[COLOR] [WORDS]      Highlight the provided words with the given color
    --disable-builtin-keywords   Disable the highlighting of all builtin groups
    --disable-booleans           Disable the highlighting of booleans and nulls
    --disable-severity           Disable the highlighting of severity levels
    --disable-rest               Disable the highlighting of REST verbs

Dependencies

~15–27MB
~424K SLoC