Colorize
Colorize is a Python program that makes it easier to understand interleaved log lines by coloring each line based on a matching part.
Source: kalgynirae/dotfiles:bin/colorize
Example:
# Color some logs from systemd based on service name $ journalctl _COMM=systemd --since -20m | grep '\.service' | colorize '\S+\.service' Jun 07 14:36:03 iroh systemd[1]: Starting NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service... Jun 07 14:36:03 iroh systemd[1]: Started NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service. Jun 07 14:36:13 iroh systemd[1]: NetworkManager-dispatcher.service: Deactivated successfully. Jun 07 14:37:59 iroh systemd[1]: Starting packagekit.service - PackageKit Daemon... Jun 07 14:37:59 iroh systemd[1]: Started packagekit.service - PackageKit Daemon. Jun 07 14:37:59 iroh systemd[1]: Starting flatpak-system-helper.service - flatpak system helper... Jun 07 14:37:59 iroh systemd[1]: Started flatpak-system-helper.service - flatpak system helper. Jun 07 14:43:09 iroh systemd[1]: packagekit.service: Deactivated successfully. Jun 07 14:43:09 iroh systemd[1]: packagekit.service: Consumed 1.177s CPU time, 120.1M memory peak. Jun 07 14:47:59 iroh systemd[1]: flatpak-system-helper.service: Deactivated successfully. Jun 07 14:51:10 iroh systemd[1]: Starting fprintd.service - Fingerprint Authentication Daemon... Jun 07 14:51:10 iroh systemd[1]: Started fprintd.service - Fingerprint Authentication Daemon. Jun 07 14:51:40 iroh systemd[1]: fprintd.service: Deactivated successfully.
Usage:
$ colorize --help
usage: colorize [-h] [--cycle] [--once] [--no-true-color] [PATTERN]
Color each output line based on the part of the line that matches PATTERN.
If PATTERN contains one or more capturing groups, only the final capturing
group will be used as the matching part of the line. Otherwise, the entire
match will be used.
positional arguments:
PATTERN what to match (default: ^[\w.-/]+)
options:
-h, --help show this help message and exit
--cycle shift color when key changes instead of assigning colors to keys
--once assign each color once; then stop coloring
--no-true-color use the terminal's color palette instead of true color