Skip to main content

Beautiful, production-ready Python logging with colors and JSON output

Project description

prettylogx

Beautiful, production-ready Python logging — zero external dependencies.

PyPI version Python License: MIT

Make your Python logs beautiful and readable in 3 lines of code.
No config files. No heavy dependencies. Just install and go.


Install

pip install prettylogx

Use

from prettylogx import setup_logger

logger = setup_logger("my-app")

logger.info("Server started")
logger.warning("Database is slow")
logger.error("Payment failed")

That's it. Your logs now look like this:

12:30:45  INFO      my-app            Server started
12:30:45  WARNING   my-app            Database is slow
12:30:45  ERROR     my-app            Payment failed

Each level prints in its own color — green, yellow, red, magenta.


More Examples

Switch to JSON logs (for production)

logger = setup_logger("my-app", json_logs=True)

logger.info("Server started")
{"timestamp": "2024-01-15T10:30:45Z", "level": "INFO", "logger": "my-app", "message": "Server started", "module": "app", "function": "main", "line": 5}

Show DEBUG level logs

logger = setup_logger("my-app", level="DEBUG")

logger.debug("Connecting to DB...")
logger.info("Connected")

Trace a request ID across all log lines

from prettylogx import setup_logger, set_request_id, clear_request_id

logger = setup_logger("api")

set_request_id("req-abc123")

logger.info("Validating input")    # → [req-abc123] Validating input
logger.info("Querying database")   # → [req-abc123] Querying database
logger.info("Returning 200 OK")    # → [req-abc123] Returning 200 OK

clear_request_id()

Log exceptions with full traceback

try:
    result = 1 / 0
except ZeroDivisionError:
    logger.exception("Something went wrong")
12:30:45  ERROR     my-app            Something went wrong
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Traceback (most recent call last):
      File "app.py", line 3, in <module>
        result = 1 / 0
    ZeroDivisionError: division by zero
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Custom log levels

logger.verbose("Very detailed info")         # below DEBUG
logger.success("Order processed!")           # between INFO and WARNING

All Options

setup_logger(
    name="my-app",       # name shown in every log line
    level="INFO",        # DEBUG / INFO / WARNING / ERROR / CRITICAL
    json_logs=False,     # True = JSON output for production
    show_time=True,      # show timestamp
    show_file=False,     # show filename and line number
    use_colors=True,     # False = plain text, no ANSI codes
)

Before vs After

Without prettylogx — raw Python logging:

Without prettylogx

No colors. No alignment. Hard to scan. Every line looks the same.


With prettylogx — beautiful, readable logs:

With prettylogx

Colors per level. Fixed columns. Request ID tracing. Clean exception blocks.


Why prettylogx?

Raw logging prettylogx
Colored output No Yes
JSON logs No Yes
Request ID tracing Manual Built-in
Clean exceptions No Yes
One-line setup No Yes
Zero dependencies Yes Yes

Roadmap

  • File handler — write to rotating log files
  • Async support via contextvars
  • Middleware for FastAPI / Flask / Django

License

MIT — free to use in personal and commercial projects.

Made by Rupesh Shinde

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

prettylogx-0.1.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

prettylogx-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file prettylogx-0.1.2.tar.gz.

File metadata

  • Download URL: prettylogx-0.1.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for prettylogx-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c68ef4d692e72dd8e3523c82e46a23dc5818ceb471b74b2d68507f56137f6da6
MD5 3a1c32c52b09a1bd5aa6ee4f7a394da6
BLAKE2b-256 f78908da2a161b8c1a996891e98ebb17b17c6d11eecdc8a8a7418a1f94a83ca1

See more details on using hashes here.

File details

Details for the file prettylogx-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: prettylogx-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for prettylogx-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7351d757bcc3a46255befafaed2779604b955e34bd8558089f825a99210872b1
MD5 e31915042f3d38b2cb7ab1aa6aeebaec
BLAKE2b-256 682854b8313854df9bba1d26563625ecfa2e5024c699dca8d07fd89d3df09a63

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