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 configure_logger
configure_logger(level="DEBUG")
logger.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
pretty-json-loguru
API
configure_logger
def configure_logger(
level: str = "DEBUG",
colorize: bool = True,
include_traceback: bool = False,
print_traceback_below: bool = True,
indent: bool = False,
remove_existing_sinks: bool = True,
keys: List[LogKey] = ["ts", "msg", "source", "extra", "error", "traceback", "level"],
):
"""Configure the Loguru logger with JSON formatting.
Args:
level: Logging level. One of ["DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"].
colorize: Adds colors to the log.
include_traceback: Adds "error" and "traceback" fields to JSON when exceptions occur.
print_traceback_below: Prints full traceback below the JSON line.
indent: Formats JSON with indentation for readability.
remove_existing_sinks: Removes existing sinks.
keys: Keys to include in the log. Available: "ts", "msg", "source", "extra", "error", "traceback", "level", "module", "function", "filename", "line", "process_name", "process_id", "thread_name", "thread_id", "name".
"""
create_json_formatter
def create_json_formatter(
colorize: bool = True,
include_traceback: bool = False,
print_traceback_below: bool = True,
indent: bool = False,
keys: List[LogKey] = ["ts", "msg", "source", "extra", "error", "traceback", "level"],
):
"""Create a JSON formatter for Loguru with optional colorization.
Args:
colorize: Adds colors to the log.
include_traceback: Adds "error" and "traceback" fields to JSON when exceptions occur.
print_traceback_below: Prints full traceback below the JSON line.
indent: Formats JSON with indentation for readability.
keys: Keys to include in the log. Available: "ts", "msg", "source", "extra", "error", "traceback", "level", "module", "function", "filename", "line", "process_name", "process_id", "thread_name", "thread_id", "name".
Returns:
A function that formats a loguru log record as a colored JSON string.
"""
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
Release history Release notifications | RSS feed
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.3.0.tar.gz
(45.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pretty_json_loguru-0.3.0.tar.gz.
File metadata
- Download URL: pretty_json_loguru-0.3.0.tar.gz
- Upload date:
- Size: 45.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed21c3ee09386cc583ef7eb154d54756cf025fd773b5d6af9145e07ed842c4fc
|
|
| MD5 |
dc3546ee3ae530e57c084c52956777fa
|
|
| BLAKE2b-256 |
4d37ca5a79827d92eba4e4c3fb8f54f967e162a33c22765811fa2bbe9355218b
|
File details
Details for the file pretty_json_loguru-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pretty_json_loguru-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6908fbcec992310d04287b5d9cc7496bfa4374c958518dda9f07d3c82e32ea0c
|
|
| MD5 |
b52aedbdc7ea97dfd39576d27ac328a4
|
|
| BLAKE2b-256 |
3f1f4516f134a411b938d067cf0558738a8a5924c2423bbd010d564acff4eea1
|