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 (before)
pretty-json-loguru (after)
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"],
) -> Callable[["Record"], str]:
"""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
Metadata
Release files for pretty-json-loguru 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pretty_json_loguru-0.3.3.tar.gz | 45.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pretty_json_loguru-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.2 kB
Release files / pretty_json_loguru-0.3.3.tar.gz
| Download URL | pretty_json_loguru-0.3.3.tar.gz |
|---|---|
| Size | 45.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85c4a2f5fd8309a249f5d1aebf8df4e44168ab1337ac3b7632a41b99c5311ac2
|
|
BLAKE2b-256 checksum How to use checksums |
7e0732ac9c1eef1ed2702845d31af222bff13bfb00e6fc2218d59ff2a1360b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Release files / pretty_json_loguru-0.3.3-py3-none-any.whl
| Download URL | pretty_json_loguru-0.3.3-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
730f06ab222e56ccedb4108cc6951531e5825ca2dbb3352933400e3db231bdc1
|
|
BLAKE2b-256 checksum How to use checksums |
36769c5d0f5b2b224a3f17aafc0b3aed33a0ef614c9e29cb943f6b08a1f64ce8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|