Logging to JSON
Yet another log to JSON library for Python.
I needed a library that integrated well with applications that mixed logging using built-in logging outputs and JSON output.
I was also unable to find a library that worked with logging.QueueHandler
Thus this library was born.
Install
pip install log-to-json
or
conda install log-to-json -c conda-forge
Example
Basic Usage
from log_to_json import JsonFormatter
import logging
logger = logging.getLogger()
handler = logging.StreamHandler()
json_formatter = JsonFormatter(keys=("name",))
handler.setFormatter(json_formatter)
logger.critical({"app-name": "my-app", "app_version": "1.0"})
# produces the log
{"app-name": "my-app", "app_version": "1.0", "name": "root"}
Slightly more advanced Usage
from log_to_json import JsonFormatter
import logging
logger = logging.getLogger()
handler = logging.StreamHandler()
def finalizer(message_dict):
"""rename name to logger_name"""
message_dict["logger_name"] = message_dict.pop("name")
return message_dict
json_formatter = JsonFormatter(
keys=("message", "name", "user"),
formatters={"user": str.upper},
finalizer=finalizer
)
handler.setFormatter(json_formatter)
logger.critical("critical failure", extra={"user": "guest"})
# produces the message
{"message": "critical failure", "user": "GUEST", "logger_name": "root"}
Notable Features
Individual Key Formatters
Finalizer
Per Message Prefix
Integrates with non-JSON Logging
Pluggable Serializer
Metadata
Release files for log-to-json 0.1.1
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 | |
|---|---|---|---|---|
| log-to-json-0.1.1.tar.gz | 5.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| log_to_json-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / log-to-json-0.1.1.tar.gz
| Download URL | log-to-json-0.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d58fcc613b8c2b284588145406e3255393680b227eaadc0399d1a759ba96b33
|
|
BLAKE2b-256 checksum How to use checksums |
45b586945496f46b5f28b263c89805c5f225c3ac27414c88db30c35f7d37f63b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
|
Release files / log_to_json-0.1.1-py3-none-any.whl
| Download URL | log_to_json-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65929f14f24c96f0af322b531eea34e67eca65297841fc6616e0edf60b8d30ad
|
|
BLAKE2b-256 checksum How to use checksums |
3df205d097ffaa59220a360dc21226e8fc39e0e150b534fb9abe08b95e828489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
|
Security for log-to-json 0.1.1
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.