Skip to main content

A UDP client for sending message in the Graylog Extended Log Format (GELF)

Project description

gelfclient

Python client for sending UDP messages in Graylog Extended Log Format (GELF).

Messages are zlib compressed, and support GELF chunked encoding.

Since messages are sent with UDP, the log method should return quickly and not raise an exception due to timeout. However an exception may be raised due to a DNS name resolution failure for the target hostname.

Installation

pip install gelfclient

Usage

from gelfclient import UdpClient

gelf_server = 'localhost'

# Using mandatory arguments
gelf = UdpClient(gelf_server)

# Using all arguments
gelf = UdpClient(gelf_server, port=12202, mtu=8000, source='macbook.local')

# Bare minimum is to send a string, which will map to gelf['short_message']
gelf.log('server is DOWN')

# 'source' and 'host' are the same. Defaults to socket.gethostname() but can be overridden
gelf.log('server is DOWN', source='hostchecker')

# Set extra fields
gelf.log('status change', _state='DOWN', _server='macbook')

# Set severity level
import syslog
gelf.log('unexpected error', level=syslog.LOG_CRIT)

# You can also prepare all data into a dictionary and give that to .log
data = {}
data['short_message'] = 'warning from python'
data['host'] = 'hostchecker'
data['level'] = syslog.LOG_WARNING
gelf.log(data)

See the GELF specification for other fields and their meaning: http://docs.graylog.org/en/latest/pages/gelf.html#gelf-format-specification

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

gelfclient-0.0.7.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file gelfclient-0.0.7.tar.gz.

File metadata

  • Download URL: gelfclient-0.0.7.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gelfclient-0.0.7.tar.gz
Algorithm Hash digest
SHA256 ace3d5718a5e844145090a5d31ed05c5fb7edd4057d00366038d8ebe6247178e
MD5 5c80e89dab7bed819b2dee72ca781cc0
BLAKE2b-256 a02d777339ff87624bfb014fd4f28e324d572a612a2291d53d797702e971b83d

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