Skip to main content

Logging handlers for sending messages into Graylog

Project description

pygelf

https://travis-ci.org/keeprocking/pygelf.svg?branch=master

pygelf allows to send logs into Graylog directly from your app using built-in logging module.

Each log message is transformed into GELF (Graylog Extended Log Format).

Currently TCP, UDP and TLS (encrypted TCP) logging handlers are supported.

Get pygelf

pip install pygelf

Usage

from pygelf import GelfTcpHandler, GelfUdpHandler, GelfTlsHandler
import logging


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(GelfTcpHandler(host='127.0.0.1', port=9401, debug=True))
logger.addHandler(GelfUdpHandler(host='127.0.0.1', port=9402, compress=True, chunk_size=1350))
logger.addHandler(GelfTlsHandler(host='127.0.0.1', port=9403, validate=True, ca_certs='/etc/ssl/certs/ca-ceritficates.crt'))

logging.info('hello gelf')

Configuration

Each handler has the following parameters:

  • host: ip address of the GELF input

  • port: port of the GELF input

  • debug (false by default): if true, each log message will include debugging info: module name, file name, line number, method name

  • version (‘1.1’ by default): GELF protocol version, can be overridden by a client

In addition UDP and TLS handlers have some specific parameters.

UDP:

  • chunk_size (1300 by default) - maximum length of the message. If log length exceeds this value, it splits into multiple chunks (see https://www.graylog.org/resources/gelf/ section “chunked GELF”) with the length equals to this value. This parameter must be less than the MTU. If the logs don’t seem to be delivered, try to reduce this value.

  • compress (true by default): if true, compress log messages before send them to the server

TLS:

  • validate (false by default) - if true, validate server certificate. If server provides a certificate that doesn’t exist in ca_certs, you won’t be able to send logs over TLS

  • ca_certs (none by default) - path to CA bundle file. This parameter is required if validate is true.

Additional fields

If you need to include some static fields into your logs, simply pass them to the handler constructor. Each additional field shoud start with underscore. You can’t add field ‘_id’.

Example:

handler = GelfUdpHandler(host='127.0.0.1', port=9402, _app_name='pygelf', _something=11)
logger.addHandler(handler)

Running tests

To run tests, you’ll need tox. After installing, simply run it:

tox

You can also specify interpreter version. For example:

tox -e py26
tox -e py35

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

pygelf-0.2.4.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file pygelf-0.2.4.tar.gz.

File metadata

  • Download URL: pygelf-0.2.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pygelf-0.2.4.tar.gz
Algorithm Hash digest
SHA256 ce2fa25f206aaab7e07f514c8d1e8b8b045e147067d3ae6bf13fd405897aae2a
MD5 f4d2d7aa9a61ab44bd874f228baa24c4
BLAKE2b-256 a6eb4fc9a6dfac2273ce3b52fb39a0c29417a691c2a8cda3ca9c887f2106e772

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