JSON formatter for graylog JSON extractor.
Project description
GrayLogJSONFormatter formatted LogRecord as JSON object for graylog JSON extractor. JSON object include LogRecord attributes as default_keys and include extra attributes: source, message, asctime and data.
Example
configure:
from logging import config config.dictConfig({ 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'graylog': { '()': 'graylog_json_formatter.GrayLogJSONFormatter', 'format': '({levelname}) | {name} | [{asctime}]: ' 'File {pathname}:{lineno}" - {funcName}() | {message}', 'style': '{', 'source': 'test', 'environment': 'testing', 'keys': { 'name', 'levelno', 'levelname', 'pathname', 'filename', 'module', 'lineno', 'funcName', 'created', 'asctime', 'msecs', 'relativeCreated', 'thread', 'threadName', 'process', 'message', 'data', 'exc_text', 'stack_info', }, 'extra': {'service': 'my-service'}, } }, 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'graylog', }, 'graylog': { 'level': 'DEBUG', 'class': 'logging.handlers.SysLogHandler', 'formatter': 'graylog', 'address': ('localhost', 10000), } }, 'loggers': { 'test': { 'level': 'DEBUG', 'handlers': ['console', 'graylog'], 'propagate': False, }, } }) logger = logging.getLogger('test')
logging:
# extra usage logger.debug('test message: % | %s', 1, 2, extra={'data': {'key': 'value', 'int_key': 12})
Graylog extract extra as data-key and data-int_key fields.
extra argument may be callable or string with dotted path to callable attribute:
'extra': lambda record: {'service': 'service-func'}
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
Close
Hashes for graylog-json-formatter-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a84a65796f65f17a32b9f4695f2c426fd9b3b29cdb83b7df8fca9dd488a412 |
|
MD5 | 643f796f10dae23f1895db374d857b47 |
|
BLAKE2b-256 | 39ec395ed9f9eb86cb0b0438d46d346fd51df59b6b34c83e1d62cb1edaf1b0d3 |
Close
Hashes for graylog_json_formatter-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 636605131e06ab3b674ed186122725fc4c2708345081597de3b4bce1021d52ba |
|
MD5 | 7b476c3dacb5a4eef9fed92b4143a81b |
|
BLAKE2b-256 | 4b623d2573da599f0d2a9e10454cca986d26cb500381cc808e8a9cc7a58a8415 |