用于以graylog扩展日志格式(gelf)发送消息的udp客户端

gelfclient的Python项目详细描述


凝胶客户机

用于以graylog扩展日志格式发送udp消息的python客户端 (盖尔夫)。

消息是zlib压缩的,并且支持gelf分块编码。

由于消息是用udp发送的,所以log方法应该很快返回 不会由于超时而引发异常。但也有例外 由于目标主机名的DNS名称解析失败而引发。

安装

pip安装gelfclient

用法

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)

其他字段及其含义见GELF规范: http://docs.graylog.org/en/latest/pages/gelf.html#gelf-format-specification

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java提高机器学习Rest服务性能   java反转字符的字符串顺序,并使用构造函数将其放入LinkedList   继承为什么Java不支持在方法签名中添加“throws”?   执行DDL alter table if exists任务时发生java错误。城市   java在eclipse中使用CREATETXT并打包在jar中   java AES256与3DES 256密钥检测   具有两个相同类型字段的java JPA实体   java Webapp日志记录设置被忽略   java KeyEventDispatcher可以在一个应用程序中工作,但不能在另一个应用程序中工作   带有Swing和OpenJDK的java PinchZoom   未涉及java AspectJ注释切入点(对于任何注释类型)   java如何在FuseBAI中获取日志文件详细信息   java在Linux上将wstring转换为jstring