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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rich_json_logs-0.2.0.tar.gz.
File metadata
- Download URL: rich_json_logs-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97362b2870f42af5927b47815194486eaa8bd8626272062baf74f062e2d00095
|
|
| MD5 |
bac375fe89f6b96a90a9cc924662cac0
|
|
| BLAKE2b-256 |
faa38cbb9eb174f0836d1edaa9ef9586749d32cc6e60a9826fa5c40af6b77268
|
File details
Details for the file rich_json_logs-0.2.0-py3-none-any.whl.
File metadata
- Download URL: rich_json_logs-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55a5b483481cee052cc74b2068d38a68a9503790937f97a5a61358b37e554d17
|
|
| MD5 |
37521d463865315a85eca2e54a5f6738
|
|
| BLAKE2b-256 |
eb8de6536c20868a5924ad10b1054658e91c64fd35949b0ea19843574f2fc50d
|