An RFC5424-Compliant Syslog Handler for the Python Logging Framework

jobec jobec Last update: Jun 28, 2022

Python rfc5424 syslog logging handler

Documentation Statushttps://travis-ci.org/jobec/rfc5424-logging-handler.svg?branch=masterhttps://codecov.io/github/jobec/rfc5424-logging-handler/coverage.svg?branch=master

An up-to-date, RFC 5424 compliant syslog handler for the Python logging framework.

Features

  • RFC 5424 Compliant.
  • Python Logging adapter for easier sending of rfc5424 specific fields.
  • No need for complicated formatting strings.
  • TLS/SSL syslog support.
  • Alternate transports like streams (ex. stderr, stdout, file, ...).

Installation

Python package:

pip install rfc5424-logging-handler

Usage

After installing you can use this package like this:

import loggingfrom rfc5424logging import Rfc5424SysLogHandlerlogger = logging.getLogger('syslogtest')logger.setLevel(logging.INFO)sh = Rfc5424SysLogHandler(address=('10.0.0.1', 514))logger.addHandler(sh)logger.info('This is an interesting message', extra={'msgid': 'some_unique_msgid'})

This will send the following message to the syslog server:

<14>1 2020-01-01T05:10:20.841485+01:00 myserver syslogtest 5252 some_unique_msgid - \xef\xbb\xbfThis is an interesting message

Note the UTF8 Byte order mark (BOM) preceding the message. While required byRFC 5424 section 6.4 if the message is known to be UTF-8 encoded,there are still syslog receivers that cannot handle it. To bypass this limitation, when initializing the handler Class,set the msg_as_utf8 parameter to False like this:

sh = Rfc5424SysLogHandler(address=('10.0.0.1', 514), msg_as_utf8=False)

For more examples, have a look at the documentation

PRAGMA foreign_keys = off; BEGIN TRANSACTION; COMMIT TRANSACTION; PRAGMA foreign_keys = on;

Subscribe to our newsletter