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
)

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.1.tar.gz (11.3 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.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prettylogx-0.1.1.tar.gz
  • Upload date:
  • Size: 11.3 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.1.tar.gz
Algorithm Hash digest
SHA256 a11090edc3333f46268b35bfc0191c57d845c57c6595759a7b746f51dc37f864
MD5 6ba50da96f9d1e47332afd9f68238b94
BLAKE2b-256 6f1db8bb463d41d4358e831b2a383d0a346bb6735190dc71bb225f895b6c03f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prettylogx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d22d33301fde6367f0602bbc8a204d606b125a5704cfef300dcee727facb54
MD5 544dfc412c723249f1a4a7f645e13b4d
BLAKE2b-256 eb41155d3e8e150075bee8b6e3afc819936a357b1b932bf953494380f5c22530

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