A formatter and set of utilities that bring pretty, highly-customizable and colored log messages to the standard logging library
Project description
Install
$ pip install plogging
Documentation
Pending... Until then, I will place some implementation code below. Before doing that, though, I
want to make a few notes on the format strings used in the formatter. Firstly, they must use the
bracket formatting style, e.g. "{a}{b!r}{c:<3}". Secondly, by default, colors are only applied
to a given field, meaning for the format string "Log time: {asctime}", only the time would be
given color. This can be changed by using the special enter and exit fields - for example:
"{enter}Log time: {asctime}{exit}", which would cause the entire area to be formatted given the
palette for asctime. Any other normal fields can also be included within the enter/exit
fields, in which case the palette for the first field would be used. Additionally, any field
prefixed with an underscore (_) will not have any formatting applied to it, though the field name
will be reverted to the non-prefixed version (e.g. _asctime -> asctime).
import plogging
import logging
# default formatter that shows a small amount of information (time,
# level name, logger name, message)
log = plogging.setup_new("logger", level=logging.DEBUG, package="test")
# the default formatter itself can be acquired as follows:
plogging.utils.default_formatter()
# you can also setup an existing logger for color formatting
log = logging.getLogger(...)
plogging.setup_existing(log, level=logging.DEBUG)
# custom formatters can also be created; here is an example:
formatter = plogging.Formatter(
fmts=plogging.LevelContainer(
debug="{asctime} {levelname:<8} {module} {message} [{threadname}, {processname}, "
"{somethingelse}]",
default="{asctime} {levelname:<8} {module} {message}"
),
datefmt="%Y-%m-%d %H:%M:%S",
defaults={
"somethingelse": "somethingelse's value"
},
asctime=plogging.Palette(
plogging.LevelContainer(
default="30;1"
)
),
levelname=plogging.Palette(
plogging.LevelContainer(
"32;1",
"34;1",
"33;1",
"31;1",
"41"
)
)
)
log = plogging.setup_new("logger", level=logging.INFO, formatter=formatter)
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 plogging-0.0.1.tar.gz.
File metadata
- Download URL: plogging-0.0.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea05da4250cfe224cbea3c6973958eb2326dc514af94beed81209467ef90868c
|
|
| MD5 |
060a3b478700cb8adc5ce5703f21e7a1
|
|
| BLAKE2b-256 |
98a51b4a00ec98e0e22b4cca6306d28d4e98523389b1dc0cc862f5534fbbf1c7
|
File details
Details for the file plogging-0.0.1-py3-none-any.whl.
File metadata
- Download URL: plogging-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02182326fe83d244cf961555d3f955d856f6faac14904de661355738325ce855
|
|
| MD5 |
39f6ef4edeb9915182c6cc40b9c86109
|
|
| BLAKE2b-256 |
341a530290efacb1cf16bc819b7ff598370e376b3ff215af2e58d30beb2a1872
|