Skip to main content

Pretty json logs in loguru

Project description

pretty-json-loguru

Pretty json python logs with loguru.

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pretty_json_loguru-0.2.1.tar.gz
Algorithm Hash digest
SHA256 df62e59be25faab3700831b23227d40a89f6bfa3b22c47b231766197b01e9560
MD5 43400ec0bf4b6ff2871f63e5313f0246
BLAKE2b-256 d62c547ec5fcde8fe281e87c62787a23adb30e35e1dea23ec271af1adc86f920

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pretty_json_loguru-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8084f487e0f27104418aed97b8c22fc52aad9d2c08aa6d89f80fb41263d8977
MD5 8ab55f1cfa738348f096bfc9ca0b9802
BLAKE2b-256 859b3c16fdcbd47abc3bf0315e87bf83f97904bd710d5d9e608d7499636f3d57

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