Skip to main content

codecov PyPI AUR github workflow pre-commit

sugarjazy - parse json logs nicely

sugarjazy is a simple tool to parse json logs and output them in a nice format with nice colors.

Usually play nicely with https://github.com/uber-go/zap when using the "Sugar" logger output.

As a tekton developer this works pretty well with tekton controllers and webhooks pods but the shoudld work as well with most knative package and other pods using go-uber/zap.

Screenshot

Default

screenshot

Stream from kail with sugarjazy

https://user-images.githubusercontent.com/98980/159916310-fabaa48e-b92a-4a41-a935-a1cb2a31e8fe.mp4

Installation

There is not many dependencies on this package but python-dateutil is an optional dependency, if the package is not installed you will not be be able to show the log timestamps.

Arch

You can install it from aur with your aurhelper, like yay :

yay -S sugarjazy

pip

With pip from pypi - https://pypi.org/project/sugarjazy/

pip install --user sugarjazy

(make sure $HOME/.local/bin is in your PATH)

git clone

you will need poetry :

git clone https://github.com/chmouel/sugarjazy
cd sugarjazy
poetry run sugarjazy

Usage

You can use sugarjazy in multiple ways :

  • By piping your logs: kubectl logs podname|sugarjazy
  • By streamining your logs: kubectl logs -f podname|sugarjazy -s
  • Directly to a file (or multiples files): sugarjazy /tmp/file1.log /tmp/file2.log
  • Using kail from https://github.com/boz/kail piping the output to sugarjazy with the --kail flag. The advantage of kail is to be able to get the logs from multiple pods and watching new events as they appears.
    • By default the prefix of the pod/container will be printed unless you specify the option --kail-no-prefix.

    • The prefix can be customized with --kail-prefix-format flag, the default template is : {namespace}/{pod}[{container}] If you want to see only the pod name you can simply do :

      `--kail-prefix-format="[{pod}]"`
      
    • The --kail flags always assume --stream implicitely.

See walkthrough documentation here

Options

usage: sugarjazy [-h] [--timeformat TIMEFORMAT]
                 [--regexp-highlight REGEXP_HIGHLIGHT]
                 [--disable-event-colouring] [--filter-level FILTER_LEVEL]
                 [--stream] [--kail] [--kail-no-prefix]
                 [--kail-prefix-format KAIL_PREFIX_FORMAT]
                 [--regexp-color REGEXP_COLOR] [--hide-timestamp]
                 [files ...]

positional arguments:
  files

options:
  -h, --help            show this help message and exit
  --timeformat TIMEFORMAT
                        timeformat default only to the hour:minute:second. Use
                        "%Y-%m-%d %H:%M:%S" if you want to add the year
  --regexp-highlight REGEXP_HIGHLIGHT, -r REGEXP_HIGHLIGHT
                        Highlight a regexp in message, eg: "Failed:\s*\d+,
                        Cancelled\s*\d+"
  --disable-event-colouring
                        By default sugarjazy will try to add a ˃ char with a
                        color to the eventid to easily identify which event
                        belongs to which. Use this option to disable it.
  --filter-level FILTER_LEVEL, -F FILTER_LEVEL
                        filter levels separated by commas, eg: info,debug
  --stream, -s          wait for input stream
  --kail, -k            assume streaming logs from kail
                        (https://github.com/boz/kail)
  --kail-no-prefix      by default kail will print the prefix unless you
                        specify this flag
  --kail-prefix-format KAIL_PREFIX_FORMAT
                        the template of the kail prefix.
  --regexp-color REGEXP_COLOR
                        Regexp highlight color
  --hide-timestamp, -H  don't show timestamp

NOTE

  • Sugarjazy tries hard to identify the same event and add all events on the same colors to the chevron character (˃).
  • The json fields are not standardize. It works well with knative based controllers like tekton or others but that may be buggy for other ones.

FAQ

  • sugarjazy is along word to type and why did the name anyway?
    • : I agree! and that's why I alias it with alias sj=sugarjazy or even better I have zsh global alias alias -g SJ=| sugarjazy -s to avoid even more typing.

Copyright

Apache-2.0

Authors

Chmouel Boudjnah <@chmouel>

Metadata

Release files for sugarjazy 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sugarjazy 0.7.1
File Size Uploaded
sugarjazy-0.7.1.tar.gz 10.2 kB Details

Release files / sugarjazy-0.7.1.tar.gz

Download URL sugarjazy-0.7.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ac847ee6f2f0ab397bed23a16362263009c5f42f0ff7730d51a24967bef62e63
BLAKE2b-256 checksum
How to use checksums
fad4f8d95624f2acc981d3c651c7b3ef4f6b58e2d6716db23ef60a38187b160e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0

Release history Release notifications | RSS feed

This release

0.7.1 This release

1 release file

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page