Skip to main content

Python logging implementation of GELF (graylog extended log format)

Project description

Get pygelf

pip install pygelf

Usage

from pygelf import GelfTcpHandler, GelfUdpHandler
import logging


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(GelfTcpHandler('127.0.0.1', 9401))
logger.addHandler(GelfUdpHandler('127.0.0.1', 9402))

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

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

In addition, UDP handler has one extra field:

  • 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-2/ 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.

Additional fields

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

Example:

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

Or using kwargs:

fields = {
    '_app_name': 'gelf_test',
    '_app_version': '1.5',
    '_something': 11
}

handler = GelfUdpHandler('127.0.0.1', 9402, **fields)
logger.addHandler(handler)

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.1.1.tar.gz (3.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pygelf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 494662d618915874bf2bae53ccf77adc7f950b612561bd1b75d3cdd8f0c69991
MD5 49bd1143224ac93cc774b3d44990d867
BLAKE2b-256 38341c4c0a9ddbb51b54af15bb6be2e6b95ced6e95aa95324b342d0e5612f2fa

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