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 | Provenance | Actions |
|---|---|---|---|---|
| pretty_json_loguru-0.3.3.tar.gz | 45.5 kB | Without provenance | Details for pretty_json_loguru-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pretty_json_loguru-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for pretty_json_loguru-0.3.3-py3-none-any.whl |
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
|
Security for pretty-json-loguru 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.