Python formatter for working with Logstash json filters.
Project description
Python logging formatter for creating log entries in a JSON logstash-friendly format.
Supports renaming of python default logging fields to logstash friendly names (e.g: renaming asctime to @timestamp)
LogstashFormatter can receive the following arguments:
fmt, list or tuple containing the fields to include in each entry. Defaults to [“asctime”, “levelname”, “filename”, “funcName”, “msg”, “exc_info”].
datefmt, date format string to be passed to formatTime(). Defaults to ISO8601 time format.
rename, dictionary containing mapping of { key: new_key } to be renamed. Defaults to { “asctime”: “@timestamp” }.
version, version as for the @version attribute used in Logstash. Defaults to “1”.
Sample output
{
"@timestamp": "2016-09-28T16:24:24,799",
"@version": "1",
"exc_info": null,
"filename": "<ipython-input-21-de248ad5b09c>",
"funcName": "<module>",
"levelname": "INFO",
"message": "This is a normal message to be logged"
}
Usage
Add LogstashFormatter as the formatter of your handler, as usual:
self.logger = logging.getLogger()
self.handler = logging.StreamHandler()
self.handler.setFormatter(LogstashFormatter())
self.logger.addHandler(self.handler)
Using in Django
Include logstash formatter in your settings file:
LOGGING = {
'formatters': {
'logstash': {
'()': 'core.logging.LogstashFormatter',
'format': ("asctime", "levelname", "name", "lineno", "message",
"pathname", "module", "funcName", "process",),
'datefmt': '%Y-%m-%dT%H:%M:%S',
'rename': {
'asctime': '@timestamp',
},
'version': '1'
},
}
}
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
Hashes for logstash-python-formatter-0.1.0b1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3d32ba3b825203739b453ce8d9e450f4e94ccdbf1e16c8f5333d69265b0b203 |
|
MD5 | e4aa7d573759a048fae5030fa6373dfa |
|
BLAKE2b-256 | 26bed8776ee8b70cd466dbf2f714f7bc267ba325097f62f03d9e0eea14b0cf69 |
Hashes for logstash_python_formatter-0.1.0b1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 156f49cd97664ed5be5947cedd9d6ea8c9c9a60a19234ba0c2eb4abc21c23114 |
|
MD5 | f7aa34319ddc31b61fbefedfd446dac3 |
|
BLAKE2b-256 | ef31397c22efc98bb1e12b911a78e20a9d9070e111405534751d1bdcd7acad7c |