PColorLogging
The powerful python logging, you can create colorful logging and easy to add logging level or record attributeReference
Installation
PColorLogging can be installed using pip as follows:
pip install PColorLogging
Usage
Here’s an example of how easy it is to get started:
import logging
from PColorLogging import DEBUG, INFO, ERROR, WARNING, CRITICAL, add_level_name
from PColorLogging.Drawer.color import PColor, TextMode
from PColorLogging.Formatter.colored_formatter import ColoredFormatter
add_level_name(25, "custom")
colored_formatter = ColoredFormatter(f"[%(asctime)s] %(levelname)s: %(message)s", [
{"config": {"message": [PColor.WHITE]}, "level": [DEBUG]},
{"config": {"message": [PColor.GREEN], "custom": [PColor.B_WHITE]}, "level": [INFO]},
{"config": {"message": [PColor.YELLOW]}, "level": [WARNING]},
{"config": {"message": [PColor.RED, TextMode.UNDERLINE]}, "level": [ERROR]},
{"config": {"message": [PColor.CYAN, TextMode.CROSS]}, "level": [CRITICAL]},
{"config": {"message": [PColor.PURPLE]}, "level": [25]},
{"config": {"asctime": [PColor.BLUE, PColor.B_WHITE]}, "level":
[DEBUG, INFO, WARNING, ERROR, CRITICAL, 25]}
])
logger = logging.getLogger()
console_handler = logging.StreamHandler()
console_handler.setFormatter(colored_formatter)
logger.addHandler(console_handler)
logger.setLevel(DEBUG)
logger.debug("this is debug")
logger.info("this is info")
logger.warning("this is warning")
logger.error("this is error")
logger.critical("this is critical")
logger.log(25, "this is custom")
If you want to add custom record attribute, you should use ExtraAdapterLogger
import logging
from PColorLogging import DEBUG, INFO, ERROR, WARNING, CRITICAL, add_level_name
from PColorLogging.Drawer.color import PColor, TextMode
from PColorLogging.Formatter.colored_formatter import ColoredFormatter
from PColorLogging.Logger.Adapter.extra_adapter_logger import ExtraAdapterLogger
add_level_name(25, "custom")
colored_formatter = ColoredFormatter(f"[%(asctime)s] %(levelname)s: %(att1)s %(att2)s %(message)s", [
{"config": {"message": [PColor.WHITE]}, "level": [DEBUG]},
{"config": {"message": [PColor.GREEN], "custom": [PColor.B_WHITE]}, "level": [INFO]},
{"config": {"message": [PColor.YELLOW]}, "level": [WARNING]},
{"config": {"message": [PColor.RED, TextMode.UNDERLINE]}, "level": [ERROR]},
{"config": {"message": [PColor.CYAN, TextMode.CROSS]}, "level": [CRITICAL]},
{"config": {"message": [PColor.PURPLE]}, "level": [25]},
{"config": {"asctime": [PColor.BLUE, PColor.B_WHITE]}, "level":
[DEBUG, INFO, WARNING, ERROR, CRITICAL, 25]}
])
console_handler = logging.StreamHandler()
console_handler.setFormatter(colored_formatter)
extra_logger = ExtraAdapterLogger("logger", {"att1": "", "att2": ""})
extra_logger.add_handler(console_handler)
extra_logger.setLevel(DEBUG)
extra_logger.debug("this is debug", extra={"att1": "att1-debug"})
extra_logger.info("this is info", extra={"att2": "att2-info"})
extra_logger.warning("this is warning", extra={"att1": "att1", "att2": "att2"})
extra_logger.error("this is error")
extra_logger.critical("this is critical")
extra_logger.log(25, "this is custom")
And then, you want to add maker function to ExtraAdapterLogger, you can use set_maker function
def makeup(base_extra):
if "att1" in base_extra:
if base_extra['att1'] == "att1-debug":
return {"att1": [PColor.GREEN, PColor.B_YELLOW]}
if "att2" in base_extra:
if base_extra['att2'] == "att2-info":
return {"att2": [PColor.B_CYAN, PColor.YELLOW]}
return None
extra_logger.set_maker(makeup)
Full example in here
Metadata
Release files for PColorLogging 0.0.34
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| PColorLogging-0.0.34.tar.gz | 8.5 kB | Without provenance | Details for PColorLogging-0.0.34.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| PColorLogging-0.0.34-py3-none-any.whl | Python 3 | none | any | Details for PColorLogging-0.0.34-py3-none-any.whl |
Total release size: 18.8 kB
Release files / PColorLogging-0.0.34.tar.gz
| Download URL | PColorLogging-0.0.34.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5293883780c640d9eb909a26acb46ea3c99c5573a542ca6de992261f9e2ed456
|
|
BLAKE2b-256 checksum How to use checksums |
5ec7651380a2dcd90ad081121db0443c4e7e3a6ea8419a94e16c2f6bd9c9b268
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.9
|
Release files / PColorLogging-0.0.34-py3-none-any.whl
| Download URL | PColorLogging-0.0.34-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eef298bf252491ba082a944195dd61ad51c8e32fa08c125a7bd392c353e67fdb
|
|
BLAKE2b-256 checksum How to use checksums |
0cfd71e61291b5a1d2ef6f32c8ad8c42889c88d72ac5367e314e5edbf6deda69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.9
|
Security for PColorLogging 0.0.34
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.