Python logging formatter for readability.
Project description
Python logging formatter for readability.
Implemented as an override for the logging.Formatter class.
Intended advantages:
readable nested traceback exception cause chains
compose message for either user, developer or log server
reusable library for consistency across multiple projects
Installation
pip install git+https://gitlab.diamond.ac.uk/scisoft/dls-logformatter.git dls-logformatter --version
Usage
import logging
from dls_logformatter.dls_logformatter import DlsLogformatter
# Make handler which writes the logs to console.
handler = logging.StreamHandler()
# Make the formatter from this library.
dls_logformatter = DlsLogformatter()
# Let handler write the custom formatted messages.
handler.setFormatter(dls_logformatter)
# Let root logger use the handler.
root_logger = logging.getLogger()
root_logger.addHandler(handler)
Example output
dls_logformatter --example long
2022-12-25 06:23:42.612463 195 MainProcess MainThread 0 0 WARNING /22/dls-logformatter/src/dls_logformatter/__main__.py[35] this is a warning message 2022-12-25 06:23:42.612568 195 MainProcess MainThread 0 0 INFO /22/dls-logformatter/src/dls_logformatter/__main__.py[36] this is an info message 2022-12-25 06:23:42.612609 195 MainProcess MainThread 0 0 INFO /22/dls-logformatter/src/dls_logformatter/__main__.py[37] this is a debug message 2022-12-25 06:23:42.612666 195 MainProcess MainThread 0 0 ERROR /22/dls-logformatter/src/dls_logformatter/__main__.py[42] this is an error message EXCEPTION RuntimeError: error in deep3 TRACEBACK /22/dls-logformatter/src/dls_logformatter/__main__.py[40] deep1() TRACEBACK /22/dls-logformatter/src/dls_logformatter/__main__.py[18] deep2() TRACEBACK /22/dls-logformatter/src/dls_logformatter/__main__.py[14] deep3() TRACEBACK /22/dls-logformatter/src/dls_logformatter/__main__.py[10] raise RuntimeError("error in deep3")
dls_logformatter --example short
0 0 WARNING dls_logformatter.__main__::example[37] this is a warning message 0 0 INFO dls_logformatter.__main__::example[38] this is an info message 0 0 INFO dls_logformatter.__main__::example[39] this is a debug message 0 0 ERROR dls_logformatter.__main__::example[44] this is an error message EXCEPTION RuntimeError: error in deep3 TRACEBACK dls_logformatter.__main__::example[42] deep1() TRACEBACK dls_logformatter.__main__::deep1[18] deep2() TRACEBACK dls_logformatter.__main__::deep2[14] deep3() TRACEBACK dls_logformatter.__main__::deep3[10] raise RuntimeError("error in deep3")
dls_logformatter --example bare
this is a warning message this is an info message this is a debug message this is an error message
Documentation
See http://www.cs.diamond.ac.uk/reports/gitlab-ci/dls-logformatter/index.html for more detailed documentation.
Building and viewing the documents locally:
git clone git+https://gitlab.diamond.ac.uk/scisoft/dls-logformatter.git cd dls-logformatter virtualenv /scratch/$USER/venv/dls-logformatter source /scratch/$USER/venv/dls-logformatter/bin/activate pip install -e .[dev,docs] make -f .dls-logformatter/Makefile validate_docs browse to file:///scratch/$USER/venvs/dls-logformatter/build/html/index.html
Topics for further documentation:
TODO list of improvements
change log
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
File details
Details for the file dls-logformatter-1.0.1.tar.gz
.
File metadata
- Download URL: dls-logformatter-1.0.1.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423da9f9c9aeb4bd9ca20ac1a480be3bf2eeba4ab87d3563248149b19c0b7aa3 |
|
MD5 | 7c2208ab7f9fba9651320f5b5d31888e |
|
BLAKE2b-256 | 6e049f23fd6b373ec974a1e5f5d8661318c0fe68e86983365b2603ceb120694b |
File details
Details for the file dls_logformatter-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: dls_logformatter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b215be53bbf830efdffbe991b6dd7a04ebaedef6c829bb5679ce71ee1e8750d |
|
MD5 | 7b0667fcf3ae6727933eb7f88724e67a |
|
BLAKE2b-256 | 18f09c924696dd274fece50d0575fe3f2bd54eb8465fefac38a574f4b29506b1 |