Skip to content

eaardal/pretty-logrus

Repository files navigation

Pretty Logrus

Takes JSON-formatted logrus log messages as input and prints them back out in a more human readable format.

Build it

go build -o plr ./...

Put the plr executable somewhere on your PATH.

Usage

kubectl logs <pod> | plr

Usage together with pod-id

Pod-id is a small utility to get the pod id from a partial pod name.

It lets you look up pods by a partial name, like this:

kubectl logs $(podid my-app)

This shell alias is useful for combining podid and plr:

alias klogs='kubectl logs $(podid $1) | plr'

To also be able to pass arguments to plr, replace the alias with this function:

klogs () {
  local pod_id
  pod_id=$(podid "$1")
  shift
  kubectl logs "$pod_id" | plr "$@"
}

# Usage examples:
klogs my-app # prints the logs from the pod where the name contains "my-app". 
klogs my-app --field trace.id # pretty-logrus arguments work as expected.

Note: The klogs function does not forward arguments to pod-id. If you need to pass arguments to pod-id, you can use the full command: kubectl logs $(podid my-app <args here>) | plr.

Options:

  • --multi-line | -M: Print output on multiple lines with log message and level first and then each data field on separate lines.
  • --no-data: Don't show any logged data fields.
  • --level <level> | -L: Only show log messages matching this level. Values (logrus levels): trace | debug | info | warning | error | fatal | panic
  • --min-level <level>: Only show log messages at this log level or higher. Severity levels: trace=1, debug=2, info=3, warning=4, error=5, fatal=6, panic=7
  • --max-level <level>: Only show log messages at this log level or lower. Severity levels: trace=1, debug=2, info=3, warning=4, error=5, fatal=6, panic=7
  • --fields <field>(,<field>) | -F: Only show specific data field(s). Several field names can be separated by comma. Field name can have leading and/or trailing wildcard *.
  • --except <field>(,<field>) | -E: Don't show this particular field or fields separated by comma. Field name can have leading and/or trailing wildcard *.
  • --trunc <field>=<num chars or substr>: Truncate the content of this field by an index or substring.
  • --where <field>=<value> | -W: Only show log messages where the value occurs.
  • --highlight-key <field> | -K: Highlight the key of the field in the output. Field name can have leading and/or trailing wildcard *. By default, this is displayed in bold red text. Styles can be overridden in the configuration file.
  • --highlight-value <field value> | -V: Highlight the value of the field in the output. Field value can have leading and/or trailing wildcard *. By default, this is displayed in bold red text. Styles can be overridden in the configuration file.
  • --all-fields: Show all data fields regardless of --except flag or fields being excluded via ExcludedFields in the config file.

--trunc examples

  • --trunc message=50: Print the first 50 characters in the message field
  • --trunc message="\n": Print everything up until the first line break in the message field
  • --trunc message="\t": Print everything up until the first tab character in the message field
  • --trunc message=mytext: Print everything up until the first occurrence of the phrase 'mytext' in the message field.
  • --trunc message="stop it": Print everything up until the first occurrence of the phrase 'stop it' in the message field.
  • --trunc message=" ": Print everything up until the first empty space in the message field.

--where examples

  • --where <field>=<value>: Only show log messages where the specific field has the given value
  • --where <field>=<value>,<field>=<value>: Specify multiple conditions separated by comma
  • --where <value>: Only show log messages where the value occurs in any data field or the message field. Value can be a partial phrase or text.

Wildcard *

Several flags support the wildcard * in their values to match several things at once:

  • --fields
  • --except
  • --highlight-key
  • --highlight-value

Usage:

  • Leading: --arg "*foo" will match phrases ending with "foo" (case sensitive).
  • Trailing: --arg "foo*" will match phrases starting with "foo" (case sensitive).
  • Both: --arg "*foo*" will match phrases containing "foo" (case sensitive).

Gotcha 1: You might need to quote the string:

--arg labels.* might give the output zsh: no matches found: labels.* whereas --arg "labels.*" will filter on fields beginning with the phrase "labels.".

Gotcha 2: it's case sensitive. For example when searching for values with --highlight-value like --highlight-value "my-service*", "my-service" will be matched as-is.

Commands

  • default-config: Prints the default configuration file to stdout
  • init: Creates a config file at the location PRETTY_LOGRUS_HOME is pointing to. It is required to set this environment variable to run this command.

Configuration file

See the configuration spec for how to set up the configuration file.

Changelog

πŸ› οΈ - Enhancements, improvements
✨ - New features, additions
πŸ› - Bug fixes
πŸ’₯ - Breaking changes
βœ‚οΈ - Remove features, deletions

v1.5.2

πŸ“† 2025-12-19

  • πŸ› Fix a bug where args were treated like commands.

v1.5.1

πŸ“† 2025-12-19

  • πŸ› οΈ Move LogLevelToSeverity map to config file. See CONFIG_FILE_SPEC for more information. This can be used to control how the --level, --min-level and --max-level flags work.

v1.5.0

πŸ“† 2025-12-19

  • ✨ Added support for config file via environment variable PRETTY_LOGRUS_HOME. See CONFIG_FILE_SPEC for more information.
  • ✨ Added support for overriding colors and styling via config file. See CONFIG_FILE_SPEC for more information. This can be useful to highlight certain fields like you want or adapt the color scheme to your terminal.
  • ✨ Added support for excluding fields from log entries via config file, if there are fields that are more noise and you don't want to see them in the output for most of the time. This basically does the same thing as the --except flag.
  • ✨ Added --all-fields flag to show all fields, including excluded ones from config file or the ones from the --except arg.
  • ✨ Addad default-config command to print the default configuration file to stdout: plr default-config.
  • ✨ Added init command to create a config file at the location PRETTY_LOGRUS_HOME is pointing to. It is required to set this environment variable to run this command: PRETTY_LOGRUS_HOME=~/.config/plr plr init

v1.4.0

πŸ“† 2025-04-01

  • ✨ Added --min-level and --max-level arguments to specify when you want to show log messages with at least or at most a certain log level severity. The log levels are ordered like this: trace=1, debug=2, info=3, warning=4, error=5, fatal=6, panic=7. Use the log level name to specify the argument, like: --min-level warning, this would only show log messages with the levels warning, error, fatal and panic.

v1.3.0

πŸ“† 2024-05-28

  • πŸ’₯ Removed the --field flag. Use --fields instead. There is no difference in usage, except --fields can do more than --field could and as such it was redundant having two really similar args. The -F shorthand alias has also been moved to --fields.
  • πŸ› οΈ Added default colors for all logrus log levels. The colors can be overridden in the configuration file.
  • πŸ› οΈ Added -E shorthand alias for the --except arg.

v1.2.2

πŸ“† 2024-05-26

  • πŸ› use path.Join() when reading config.json to avoid OS-related file path issues.
  • πŸ› misc refactoring and cleanup.

v1.2.1

πŸ“† 2024-05-26

  • πŸ› οΈ Add shorthand aliases to some CLI arguments.
  • πŸ› Fix various style-related bugs.

v1.2.0

πŸ“† 2024-05-24

  • ✨ Added a configuration file to customize various aspects of the app, like the text styles. See the configuration file spec for more information.
  • ✨ Added --highlight-key and --highlight-value flags to highlight specific fields or values in the output.

☝️ Highlighting the key trace.id (--highlight-key trace.id).

☝️ Highlighting all values containing abc (--highlight-value "*abc*").

v1.1.6

πŸ“† 2024-05-24

  • πŸ› οΈ Fields are sorted alphabetically.
  • πŸ› οΈ Include (--field, --fields) and exclude (--except) flags can now take a wildcard * to match several fields at once.

v1.1.5

πŸ“† 2024-04-08

✨ Added --where flag to filter log messages based on field values. Example: --where trace.id=1234. See usage examples above for more variations.

v1.1.4

πŸ“† 2023-03-13

  • πŸ› οΈ Support tailing like kubectl logs -f | plr

v1.1.3

πŸ“† 2022-10-24

  • πŸ› οΈ A field named labels will be treated as a map of other sub-fields and each sub-field under labels will be printed as labels.<subfield>=[<value>]. Example:

Before

labels=[map[string]struct{ foo: "bar", abc: "def" }]

After

labels.foo=[bar] labels.abc=[def]

v1.1.2

πŸ“† 2022-10-06

  • πŸ› If a log line cannot be parsed (i.e. if it's not a line with JSON on the expected logrus format), it will be printed as-is instead of being ignored by the error handler.

v1.1.1

πŸ“† 2022-10-04

  • πŸ› οΈ Truncate flag now supports substrings, newline and tab characters in addition to a character index.

v1.1.0

πŸ“† 2022-10-04

  • ✨ Added --trunc flag to limit the output length of a certain field. The value of the given field name will be cut off at the given character index. Only one field can be truncated at a time. Example: --trunc service.name=10.
  • πŸ› Fixed a bug where long lines would be skipped entirely and the line would be lost without any warning or information.

v1.0.0

No changelog at this time

About

Prints JSON-formatted logrus log messages in a more human readable format

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published