Skip to main content

Send syslog data over a TCP/TLS socket.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

build license kit format

This library allows sending syslog messages over TCP and TLS, similar to how Python’s built-in SysLogHandler sends log lines over UDP. Since TCP isn’t fire-and-forget like UDP, this library uses a daemon thread to send log-lines in the background without blocking the main application thread. Shutdown of the main process, however, is blocked until all log lines in the send-queue have been sent.

Installation

The documentation below assumes you’re configuring the library to send logging to Papertrail, since Papertrail is a commonly used rsyslog provider that supports TCP/TLS connections. The same instructions should be applicable to any TCP/TLS syslog listener.

Obtain the TLS CA Certificates

Download the syslog listener’s TLS certificates file in PEM format and save it somewhere. For example:

curl -o /path/to/papertrail-bundle.pem https://papertrailapp.com/tools/papertrail-bundle.pem

This step isn’t needed is you aren’t planning to validate the listener’s certificate, but you should always validate the certificate. Otherwise, you might as well continue using syslog over UDP.

Setup: Django

The below sample code, when placed in your project’s settings.py file, configures Django’s logging framework.

import ssl

syslog_host = 'logsX.papertrailapp.com'
syslog_port = 55555
syslog_cert_path = '/path/to/papertrail-bundle.pem'

LOGGING = {
    'version': 1,
    'formatters': {
        'simple': {
            'format': '%(asctime)s django %(name)s: %(levelname)s %(message)s',
            'datefmt': '%Y-%m-%dT%H:%M:%S',
        },
    },
    'handlers': {
        'syslog': {
            'level': 'INFO',
            'class': 'tlssyslog.handlers.TLSSysLogHandler',
            'formatter': 'simple',
            'address': (syslog_host, syslog_port),
            'ssl_kwargs': {
                'cert_reqs': ssl.CERT_REQUIRED,
                'ssl_version': ssl.PROTOCOL_TLS,
                'ca_certs': syslog_cert_path,
            },
        },
    },
    'root': {
        'handlers': ['syslog'],
        'level': 'INFO',
    }
}

Setup: Generic Python Application

The below sample code configures Python’s logging framework.

import logging.config
import ssl

syslog_host = 'logsX.papertrailapp.com'
syslog_port = 55555
syslog_cert_path = '/path/to/papertrail-bundle.pem'

logging.config.dictConfig({
    'version': 1,
    'formatters': {
        'simple': {
            'format': '%(asctime)s django %(name)s: %(levelname)s %(message)s',
            'datefmt': '%Y-%m-%dT%H:%M:%S',
        },
    },
    'handlers': {
        'syslog': {
            'level': 'INFO',
            'class': 'tlssyslog.handlers.TLSSysLogHandler',
            'formatter': 'simple',
            'address': (syslog_host, syslog_port),
            'ssl_kwargs': {
                'cert_reqs': ssl.CERT_REQUIRED,
                'ssl_version': ssl.PROTOCOL_TLS,
                'ca_certs': syslog_cert_path,
            },
        },
    },
    'root': {
        'handlers': ['syslog'],
        'level': 'INFO',
    }
})

Changelog

0.1.0

  • Initial release.

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

tls-syslog-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tls_syslog-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tls-syslog-0.1.0.tar.gz.

File metadata

  • Download URL: tls-syslog-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tls-syslog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4fac90017f19f1a4ca6dc8f087325ec3aa4ffc737c6a574a2bc5ddf8940fb3d
MD5 a59672875e8bc4936378b38237466356
BLAKE2b-256 2fa47ff4e187c73f87d17e45be25760f9f595a8ce5e994ae6d1b02b677a7bd0d

See more details on using hashes here.

File details

Details for the file tls_syslog-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tls_syslog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c51bf921d16fe2e94337b9e8438cb084367f9e011377486640160b2d6737818
MD5 5ed148fb1ed80b1f681103ee61df64d9
BLAKE2b-256 7387a635ee33509f865e53a445280c725872206b75ee98385a00fbb779e379cb

See more details on using hashes here.

Supported by

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