ColouredLogger
coloured-logger is a Python package that provides a customised logger with coloured output and the ability to set verbosity levels dynamically.
Installation
You can install My Coloured Logger using pip:
pip install coloured-logger
Usage
As all the good loggers you simply use it as the standard logger
from coloured_logger import Logger
logger = Logger(__name__) # Or any other name you want
logger.info("This is an informational message.")
logger.debug("This debug message won't be displayed.")
Colour scheme is customisable by user using the ANSI escape codes for colours. These are typically defined in terms of foreground and background colours, and each color has an associated numeric code. Here is a common mapping:
Colour codes
Most terminals support 8 and 16 colours, as well as 256 (8-bit) colours. These colours are set by the user, but have commonly defined meanings.
8-16 Colours
| Colour Name | Foreground Colour Code | Background Colour Code |
|---|---|---|
| Black | 30 |
40 |
| Red | 31 |
41 |
| Green | 32 |
42 |
| Yellow | 33 |
43 |
| Blue | 34 |
44 |
| Magenta | 35 |
45 |
| Cyan | 36 |
46 |
| White | 37 |
47 |
| Default | 39 |
49 |
| Reset | 0 |
0 |
Note: the Reset colour is the reset code that resets all colours and text effects, Use Default colour to reset colours only.
Most terminals, apart from the basic set of 8 colors, also support the "bright" or "bold" colours. These have their own set of codes, mirroring the normal colours, but with an additional ;1 in their codes:
# Set style to bold, red foreground.
\x1b[1;31mHello
# Set style to dimmed white foreground with red background.
\x1b[2;37;41mWorld
A simplified configuration
The user can simply define a python dictionary in order to change logger colours with a simplified colour scheme.
Configure logger colours
In order to configure the logger colours, the user can use the following code
from coloured_logger import Logger
my_custom_colours = {
"WARNING": 4, # Yellow background with blue text
"INFO": 2, # Green text
"DEBUG": 6, # Cyan text
"CRITICAL": 1, # Red text
"ERROR": 5 # Magenta text
}
# This can change the logger level
logger_level = "DEBUG"
logger = Logger(__name__, my_custom_colours, logger_level)
Metadata
Release files for coloured-logger 1.0.3
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 |
|---|---|---|---|---|
| coloured-logger-1.0.3.tar.gz | 5.1 kB | Without provenance | Details for coloured-logger-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coloured_logger-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for coloured_logger-1.0.3-py3-none-any.whl |
Total release size: 11.1 kB
Release files / coloured-logger-1.0.3.tar.gz
| Download URL | coloured-logger-1.0.3.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba6860028630bb933e0dd1da710e72fdc815906a41701e0cffbad6914848e699
|
|
BLAKE2b-256 checksum How to use checksums |
10877402c13b137b022360739e35df0f5e078bd4b3199ec119dfe56688328685
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / coloured_logger-1.0.3-py3-none-any.whl
| Download URL | coloured_logger-1.0.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9ded202bdad595afa84f00ddd4f4c5d415e35d772d1f76e710572e7a34c8585
|
|
BLAKE2b-256 checksum How to use checksums |
14d79c3540e029f5f0ddda1cac36e74ef33911fc8e143cc150874350c62c8789
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for coloured-logger 1.0.3
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.