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 (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
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.3.tar.gz
(45.5 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.3.tar.gz.
File metadata
- Download URL: pretty_json_loguru-0.3.3.tar.gz
- Upload date:
- Size: 45.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85c4a2f5fd8309a249f5d1aebf8df4e44168ab1337ac3b7632a41b99c5311ac2
|
|
| MD5 |
3b095a48dbd568feb59f7d7bc2adb806
|
|
| BLAKE2b-256 |
7e0732ac9c1eef1ed2702845d31af222bff13bfb00e6fc2218d59ff2a1360b61
|
File details
Details for the file pretty_json_loguru-0.3.3-py3-none-any.whl.
File metadata
- Download URL: pretty_json_loguru-0.3.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
730f06ab222e56ccedb4108cc6951531e5825ca2dbb3352933400e3db231bdc1
|
|
| MD5 |
61adf4a05a14774f4ce91ebd9b41f7e4
|
|
| BLAKE2b-256 |
36769c5d0f5b2b224a3f17aafc0b3aed33a0ef614c9e29cb943f6b08a1f64ce8
|