Created
December 11, 2013 06:23
-
-
Save svartalf/7905857 to your computer and use it in GitHub Desktop.
python log handler for fluent tcp transport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from logging.handlers import SocketHandler | |
import msgpack # https://pypi.python.org/pypi/msgpack-python | |
class FluentdHandler(SocketHandler): | |
def __init__(self, host='localhost', port=24224): | |
super(FluentdHandler, self).__init__(host, port) | |
self.packer = msgpack.Packer(encoding='utf-8') | |
def makePickle(self, record): | |
tag = '{0}.{1}'.format(record.name, record.funcName) | |
data = { | |
'level': record.levelname, | |
'message': record.msg % record.args, | |
'line': '{0}.{1}:{2}'.format(record.name, record.funcName, record.lineno), | |
} | |
return self.packer.pack([tag, record.created, data]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment