Skip to main content

Json Log Formatter

Project description

==================

`Repository <https://bitbucket.org/bear_belly/json_log_formatter>`__

Formats log output in JSON format. Shows all fields of a log record.

Here is an example of the output.

::

...
{
"name": "somemodule.util",
"msg": "This is a log message",
"args": "()",
"levelname": "DEBUG",
"levelno": "10",
"pathname": "/path/to/pyfile.py",
"filename": "util.py",
"module": "util",
"exc_info": "None",
"exc_text": "None",
"stack_info": "None",
"lineno": "217",
"funcName": "do_something",
"created": "1520373828.7142632",
"msecs": "714.2632007598877",
"relativeCreated": "2531.79669380188",
"thread": "140244615616320",
"threadName": "MainThread",
"processName": "MainProcess",
"process": "11519"
}
{
"name": "somemodule.util",
"msg": "This is an error message",
"args": "()",
"levelname": "ERROR",
"levelno": "10",
"pathname": "/path/to/otherfile.py",
"filename": "util.py",
"module": "util",
"exc_info": "None",
"exc_text": "None",
"stack_info": "None",
"lineno": "217",
"funcName": "do_something",
"created": "1520373218.7142632",
"msecs": "810.2632007598877",
"relativeCreated": "8531.79669380188",
"thread": "140244615616320",
"threadName": "MainThread",
"processName": "MainProcess",
"process": "11519"
}
...

Installation
------------

Install as you would any other python package::

::

$ pip install json-log-formatter

Usage
-----

To use the formatter, include it in logging config as you would other
formatters.

The formatter takes one optional argument ``json_kwargs``. These are
keywords that are passed directly to
```json.dumps()`` <https://docs.python.org/3/library/json.html#json.dumps>`__.

YAML Example
~~~~~~~~~~~~

::

logging:
version: 1
formatters:
...
json:
class: json_log_formatter.JsonFormatter
json_kwargs:
indent: 2
...
handlers:
....
json_console:
class: logging.StreamHandler
formatter: json
...
loggers:
...
console:
level: DEBUG
handler: json_console
...
root:
...
level: DEBUG
handlers: [json_console, ]
...

Dict example
~~~~~~~~~~~~

::

'logging': {
'version': 1,
'formatters': {
...
'json': {
'class': 'json_log_formatter.JsonFormatter',
'json_kwargs': {
indent: 2
...
},
...
},
...
},
'handlers': {
....
'json_console': {
'class': 'logging.StreamHandler',
'formatter': 'json',
},
...
},
'loggers': {
...
'console': {
'level': 'DEBUG',
'handler': 'json_console',
},
...
},
'root': {
...
'level': 'DEBUG',
'handlers': ['json_console', ]
...
},
...
}

Home-page: UNKNOWN
Author: Jordan Hewitt
Author-email: jordan.h@startmail.com
License: GPLv3
Description: UNKNOWN
Keywords: json log output format flannel
Platform: UNKNOWN

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

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page