Skip to main content

No project description provided

Project description

Readme

Colored-logs is a command line tool written in Python that allows to visualize logs in a tabular format.

By default it tries to parse json logs and extract the relevant columns passed as options. If a list of columns is not provided it uses the default value @timestamp,log.level,message. You can also use jsonpath to extract nested json columns (even with . in the column name) like @timestamp,log.logger,$.'log.origin'.'file.name',message. In case a column is not present in a json line, the value for that column will be filled with - instead.

In case the logs are not json, it will avoid parsing the text and insert it as the last column of the table.

You can either use the script to visualize logs from a file on your local filesystem with ndjson format (1 json per line)

python main.py -i sample.log

or otherwise read from Stdin using a pipe command

cat sample.log | python main.py | less -r

In the first example, the python script already comes with a pager, while in the second example you need to use an external pager. Here less -r supports colored output.

Install

You need to install some required libraries that are listed on requirements.txt

pip install -r requirements.txt

Help

In order to see the list of supported options, you can issue the following command

 python main.py --help                          
Usage: main.py [OPTIONS]

Options:
  -i, --input-path TEXT  Input path
  -c, --columns TEXT     Columns to filter
  --help                 Show this message and exit.

Kubectl plugin

Colored-logs can be used as a kubectl plugin by wrapping it in a bash script

#!/bin/bash
/usr/local/bin/kubectl logs $1 -n $2 --context $3 \
        | python main.py \
        | less -r

I have attached the following script at bin/kubectl-rich.sh. In order to use it as a kubectl plugin, the following script needs to be added to the PATH environment variable.

Finally it can be used as following

kubectl rich <pod-name> <namespace> <context>

K9s plugin

You can also use the kubectl plugin here provided as a K9s plugin by adding the following entry to the ~/.k9s/plugin.xml file. Once you are inside k9s on the Pod view, you can type ctrl+j to use colored-logs to visualize logs in a tabular form.

plugin:
  rich:
    shortCut: Ctrl-J
    confirm: false
    description: "Logs (rich)"
    scopes:
      - po
    command: kubectl
    background: false
    args:
      - rich
      - $NAME
      - $NAMESPACE
      - $CONTEXT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_json_logs-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_json_logs-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file rich_json_logs-0.1.0.tar.gz.

File metadata

  • Download URL: rich_json_logs-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/21.6.0

File hashes

Hashes for rich_json_logs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3c678f608f8eeca97e17377c83b12dedea660242545d9aa1c02a77499265122
MD5 612d05452fc290dc95535684ea435ec2
BLAKE2b-256 eaf204a7c23c1a296cf1ad756efe1c0c62dc7114a10d6eb2245dc59866221f35

See more details on using hashes here.

File details

Details for the file rich_json_logs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rich_json_logs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/21.6.0

File hashes

Hashes for rich_json_logs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d441ce57ced2f02ae65a60ea554436b7867bfba92269896c2af796da83a9169e
MD5 d4dae281d800b98a953fbeccdf12001b
BLAKE2b-256 a1b1f1c9d2709c926924e261a1aba82414700df299cdacaeb2e05a0530f93594

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page