Simple log formatter for Logstash-compatible JSON output
Project description
This is a fork of simple_json_logger, extracting the formatter into it’s own project.
It formats the Python logging.Record into a JSON suitable for indexing engines like Logstash and AWS CloudWatch Logs.
Installation
pip install simple_json_logging_formatter
Usage
Simply set the formatter in a log handler and add it to the current logger.
For example, to print the JSON logs to the current stream, set up the logger with the following:
import json, logging
from simple_json_log_formatter import SimpleJsonFormatter
handler = logging.StreamHandler()
handler.setFormatter(SimpleJsonFormatter(json.dumps))
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)
And then simply call logging.info('TEST'). It should print something like this:
{"timestamp": "2017-09-08T17:01:26.408975", "line_number": 1, "function": "<module>", "module": "<input>", "level": "INFO", "path": "<input>", "msg": "TEST"}
Testing
python setup.py test
Compatibility
Python versions 3.4+ are supported.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for simple_json_log_formatter-0.4.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f9a152c7266abafdaf85ffadb9f9f7fa65e011aeeddadf7a1c0f84dfbeaee9 |
|
MD5 | 749a94ef72c3f24d17c7f570bf29cd91 |
|
BLAKE2b-256 | f82511147e1e0df3266ec379ba22f88a589e859b301492a73653209b925d8125 |