Metadata-Version: 2.4
Name: pretty-json-loguru
Version: 0.2.1
Summary: Pretty json logs in loguru
Author-email: Mark Lidenberg <marklidenberg@gmail.com>
License: MIT
License-File: LICENSE
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.8
Requires-Dist: loguru>=0.6.0
Requires-Dist: pytest>=8.3.5
Requires-Dist: retry>=0.9.2
Provides-Extra: dev
Requires-Dist: better-exceptions>=0.3.3; extra == 'dev'
Requires-Dist: build>=1.2.2.post1; extra == 'dev'
Requires-Dist: load-dotenv>=0.1.0; extra == 'dev'
Requires-Dist: questionary>=2.1.0; extra == 'dev'
Requires-Dist: twine>=6.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# pretty-json-loguru

Pretty json python logs with [loguru](https://github.com/Delgan/loguru).

## Basic usage 

```python

from pretty_json_loguru import setup_json_loguru

setup_json_loguru(level="DEBUG")

```


## How it looks 

### loguru

![Before](docs/logger_default.png "Before")

### pretty-json-loguru

![After](docs/logger_pretty_json_loguru.png "After")

## Why JSON logs? 

- Clear for developers and parsers alike.
- Paste into any JSON viewer to expand and explore fields.

## API

```python
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.