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 DlsLogform
# Make handler which writes the logs to console.
handler = logging.StreamHandler()
# Make the formatter from this library.
dls_logformatter = DlsLogform()
# 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.0.tar.gz
.
File metadata
- Download URL: dls-logformatter-1.0.0.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 | 5a489addf7e3fbe706ac8e3ce00f6efef83eafaccb23e237f1c4ec9c91e4bf9a |
|
MD5 | 11b4fd84728fc36e0e86da59a3dae269 |
|
BLAKE2b-256 | 725ee868028539e07e7d7f2d3da0a113c74e01457ccf823ad70b5acfd8934e56 |
File details
Details for the file dls_logformatter-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: dls_logformatter-1.0.0-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 | 8f363580f2d2a59efc47ed6a01810a935ed3ab149670df29277c20e0e191cd82 |
|
MD5 | 3c2e9e5f7fbee33446e0dc5f8f1c735d |
|
BLAKE2b-256 | 6b0ac962d88e13a09d9e66aac942fa67c9a891a50ac84f9231d1e09e247fa8be |