Skip to main content

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'}

Metadata

Release files for graylog-json-formatter 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graylog-json-formatter 1.0.1
File Size Uploaded Provenance Actions
graylog-json-formatter-1.0.1.tar.gz 3.7 kB Without provenance Details for graylog-json-formatter-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graylog-json-formatter 1.0.1
File Interpreter ABI Platform Actions
graylog_json_formatter-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for graylog_json_formatter-1.0.1-py2.py3-none-any.whl

Total release size: 9.3 kB

Release files / graylog-json-formatter-1.0.1.tar.gz

Download URL graylog-json-formatter-1.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bf832f6c9440773f3bd669025a7ad3546df657ff5938aa81d319ab87470c6651
BLAKE2b-256 checksum
How to use checksums
999710b824a56364cab56a0fa842c5baa944c2a9a22a43e6c182910029ab1521
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Release files / graylog_json_formatter-1.0.1-py2.py3-none-any.whl

Download URL graylog_json_formatter-1.0.1-py2.py3-none-any.whl
Size 5.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
95ab145b1b28dff2195f3aed0a99948463e656f9ab8e19d229f3c8c3fcbf0e75
BLAKE2b-256 checksum
How to use checksums
ee6d336cc214509da2a6b8103904a34b721fc64eaab55f41d218959b6cd3052a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Security for graylog-json-formatter 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page