Yet another package to convert log messages to JSON.
Project description
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
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
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 log-to-json-0.1.1.tar.gz.
File metadata
- Download URL: log-to-json-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d58fcc613b8c2b284588145406e3255393680b227eaadc0399d1a759ba96b33
|
|
| MD5 |
5ccaa79ca9b0b3a042ceff35d3e61987
|
|
| BLAKE2b-256 |
45b586945496f46b5f28b263c89805c5f225c3ac27414c88db30c35f7d37f63b
|
File details
Details for the file log_to_json-0.1.1-py3-none-any.whl.
File metadata
- Download URL: log_to_json-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65929f14f24c96f0af322b531eea34e67eca65297841fc6616e0edf60b8d30ad
|
|
| MD5 |
928ba998fa9cc85c9be0fd325dbb4c6a
|
|
| BLAKE2b-256 |
3df205d097ffaa59220a360dc21226e8fc39e0e150b534fb9abe08b95e828489
|