Skip to main content

Pretty Python JSON logs

Project description

pretty-json-loguru

Pretty Python JSON logs with loguru.

Basic usage

from loguru import logger
from pretty_json_loguru import setup_json_loguru

setup_json_loguru(level="DEBUG")

loguru.debug("Hello", who="Friend!")

Why JSON logs?

  • Optimized for both developers and automated parsers
  • Load large logs into any JSON viewer to expand and inspect every field

How it looks

Vanilla loguru

Before

pretty-json-loguru

After

API

def setup_json_loguru(
    level: str = "DEBUG",
    traceback: Literal["attach", "extra", "drop"] = "attach",
    colorize: bool = True,
    remove_existing_sinks: bool = True,
    keys: List[str] = ["ts", "msg", "source", "extra", "error", "traceback", "level"],
):
    """Set up pretty-json-loguru logger.

    Parameters
    ----------
    level : str
        Logging level. One of `["DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"]`.
    
    traceback : Literal["attach", "extra", "drop"]
        "attach" appends the traceback to the log;
        "extra" adds it to the extra field;
        "drop" discards it.
    
    colorize : bool
        Adds colors to the log.
    
    keys : List[str]
        Keys to include in the log from the list `["ts", "msg", "source", "extra", "error", "traceback", "level", "module"]`.
        `module` is the only key that's not included by default.
        `extra` is a placeholder for extra fields.

    remove_existing_sinks : bool
        Removes existing sinks.
...

better_exceptions

Install better-exceptions for prettier tracebacks (used by default in loguru if installed)

License

MIT License

Author

Mark Lidenberg marklidenberg@gmail.com

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

pretty_json_loguru-0.2.2.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

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

pretty_json_loguru-0.2.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pretty_json_loguru-0.2.2.tar.gz.

File metadata

  • Download URL: pretty_json_loguru-0.2.2.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for pretty_json_loguru-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b82d8b1d7fa7482deb5367c0c1e3282a2631a1a5d11862faac7af2f612816246
MD5 71ec4ef04fd68d8c2e27994201a3ebe1
BLAKE2b-256 93c95e6bd5c455aaf9f8dbcfd55379b0d8935232b1925eb8ea0155b2ce2ae60e

See more details on using hashes here.

File details

Details for the file pretty_json_loguru-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pretty_json_loguru-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fae072a5fea6137592448182140104bec069d2a6e430a3f4b68b020556f1cf77
MD5 3c465b42784d746b14c9c4a24855391f
BLAKE2b-256 755ba7c211886641021bbb3abd562d53b1018a9977b9a043e6f7e1bfd9a98aa8

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