A color-coded JSON pretty printer for Python.
Project description
Colory PPrint
Colory PPrint is a Python logging package that outputs color-coded and formatted JSON logs. It allows for easy-to-read logs with foreground and background color customizations, text styles (like bold, underline), and ensures that even non-serializable objects are logged correctly.
Features:
- Color-coded JSON logs with support for foreground and background colors.
- Supports various text styles such as bold, underline, reverse, and concealed.
- Customizable logging for Python applications, ideal for debugging and data visualization.
- Handles non-serializable objects gracefully by displaying their type and memory address.
Installation
You can install the package via pip from the GitHub repository:
pip install git+https://github.com/ruhiddin/colory-pprint.git
Also , you can install it via pip from PyPI:
pip install colory_pprint
Alternatively, you can clone the repository and install manually:
git clone https://github.com/ruhiddin/colory-pprint.git
cd colory-pprint
pip install .
Usage
Basic Usage:
from colory_pprint import ColoryPPrint
log = ColoryPPrint()
log({"message": "Hello, World!"})
Logging with Colors and Styles:
You can chain colors, background colors, and styles:
log.red.bold({"status": "error", "message": "An error occurred!"})
log.green.on_black.underline({"status": "success", "message": "Operation successful."})
Handling Non-Serializable Objects:
The logger can handle non-serializable objects (e.g., custom objects) and log their repr():
class CustomObject:
def __init__(self, name: str, value: int):
self.name = name
self.value = value
custom_obj = CustomObject(name="Test", value=100)
log.red.bold({
"status": "error",
"message": "An error occurred!",
"object": custom_obj
})
The output will show:
{
"status": "error",
"message": "An error occurred!",
"object": "<CustomObject object at 0x7f8a3f8b93d0>"
}
Available Colors:
- Foreground: black, red, green, yellow, blue, magenta, cyan, white, grey, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, light_white.
- Background: on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white, on_grey, on_light_red, on_light_green, on_light_yellow, on_light_blue, on_light_magenta, on_light_cyan, on_light_white.
Available Text Styles:
- bold
- underline
- reverse
- concealed
Debug Mode:
Pass debug=True to the logger to enable debug mode because by default it is False so you won't see any logs. (Do not forget to set it to False in Production):
log = ColoryPPrint(debug=True)
log({"message": "Debug mode enabled!"})
This will print the JSON output with applied styles and formatting, allowing you to verify that the data is being serialized as expected.
Project details
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 colory_pprint-1.2.0.tar.gz.
File metadata
- Download URL: colory_pprint-1.2.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42bba2fcf4a8936c5e884ef7f3e2de13cec9e5d9c20acb24bc5fa55182e4af58
|
|
| MD5 |
71b5334daaba30590bec6e55319a97df
|
|
| BLAKE2b-256 |
ba0097ef0e3a749c3ecb6f34508068c8692e6f27ea6293374fe617b3325dd803
|
File details
Details for the file colory_pprint-1.2.0-py3-none-any.whl.
File metadata
- Download URL: colory_pprint-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf6b63dad1a9d6b7e3827f6d5e612f2740ff3ed8871abe14f0c17fcb4d5855a1
|
|
| MD5 |
ac2a6ae0998367155abe42113f5cb864
|
|
| BLAKE2b-256 |
371529cdacce958584236b11769e21b87298d2fcdc78251b6cdd11ab0ed3816c
|