Skip to main content

Pretty json logs in loguru

Project description

pretty-json-loguru

Pretty json loguru logs.

Basic usage

from pretty_json_loguru import setup_json_loguru

setup_json_loguru(level="DEBUG")

How it looks

loguru

Before

pretty-json-loguru

After

Why JSON logs?

  • Clear for developers and parsers alike.
  • Paste into any JSON viewer to expand and explore fields.

API

from typing import Literal, List


def setup_json_loguru(
        level: str = "DEBUG",
        traceback: Literal["attach", "extra", "drop"] = "attach",
        colorize: bool = True,
        remove_existing_sinks: bool = True,
        keys: List[Literal["ts", "module", "msg", "source", "extra", "error", "traceback", "level"]] = [
            "ts",
            # "module", # module is skipped by default for brevity
            "msg",
            "source",
            "extra",
            "error",
            "traceback",
            "level",
        ],
):
    """Set up loguru logger with JSON format (colored).

    Parameters
    ----------
    level : str
        Logging level
    traceback : Literal["attach", "extra", "drop"]
        If "attach", traceback will be appended to the log, as if we use the vanilla formatter.
        if "extra", traceback will be added to the extra field
        if "drop", traceback will be dropped
    colorize : bool
        If True, colors will be added to the log. If colorize=False, vanilla traceback will be used (`traceback.format_exc()`)
     keys : List[Literal["ts", "module", "msg", "source", "extra", "error", "traceback", "level"]]
        List and order of keys to include in the log. `extra` is a placeholder for extra fields
    remove_existing_sinks : bool
        Whether to remove existing sinks
    """
	...

better_exceptions

Install better_exceptions for prettier tracebacks, used by default by loguru.

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.0.tar.gz (488.9 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.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pretty_json_loguru-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8c598146301c9d0e1b6ddac50c995b6165950a9bdb9ca046da7e536cb6ef903e
MD5 366ea5bef83169c3dbb5b495287a98d3
BLAKE2b-256 cb254ab9deb8d2875eca8b040b7fb4a836feedc57d2b547987d8ca1254cf7680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pretty_json_loguru-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e850ece031abc5589f9ee0c6476cee2edff618ea1de102c4a0cc1ec081e09614
MD5 413299c7021dc6600d6e9c5f6e2194c6
BLAKE2b-256 7ec4ee2ee874536356ce27d2b9ce44944c9c4155335e2bb4aede4cb026961870

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