Skip to main content

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

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:

You can enable debug mode to print raw JSON data:

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

colory_pprint-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colory_pprint-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file colory_pprint-1.0.0.tar.gz.

File metadata

  • Download URL: colory_pprint-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for colory_pprint-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cd26b61524cf1c419858bb329bec1ed2a1e4bd8cb3ee0629b6fcb6d868a224a5
MD5 99efaf40c8b4d33a559511f2059bd3b4
BLAKE2b-256 d4632b766a8e2ef4a6c81527a17bee9a0a36d0322cc1a0a6be764070c9b1a545

See more details on using hashes here.

File details

Details for the file colory_pprint-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: colory_pprint-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for colory_pprint-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2caabed5290e000234a8310106c91803ce7d1283a505c447d68ceb0dae33f2c
MD5 9bc03c58988e2eb42250939f26a7eff5
BLAKE2b-256 9d745e0bf77e25232e0a21ad87b83e512aa0a2c0dde15eb37ddc1cd5daa2e1ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page