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

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

colory_pprint-1.3.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.3.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: colory_pprint-1.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 22df19a100712fb62b954ef855cd1674c77cb9eb472520656c0b97eda3a37ed0
MD5 8d71bce1e92b571a23ce8214bed2d9cb
BLAKE2b-256 bf02adc39315396a9fd473da17c0ab527bb385c6ff96e3c84b5e1a9d676ed934

See more details on using hashes here.

File details

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

File metadata

  • Download URL: colory_pprint-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d8384242556837ca19c349d67fd7bacc9c7e622d5e0e0790fabaf8b0517aa51
MD5 8833e776d50ce39ef0ec82e5c8547c07
BLAKE2b-256 011a7174a9cd51381c9bf8b390b45a23c65da96a9035536431041a02f6c5e037

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