Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ This client-library also has FluentHanler class for Python logging module.

logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')
l.addHandler(handler.FluentHandler('app.follow', host='host', port=24224))
h = handler.FluentHandler('app.follow', host='host', port=24224)
h.setFormatter(handler.FluentRecordFormatter())
l.addHandler(h)
l.info({
'from': 'userA',
'to': 'userB'
Expand Down
21 changes: 19 additions & 2 deletions fluent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
import logging
import socket

# This is a patch to make the code cross-compatible between python 2 and 3
# Source: http://www.rfk.id.au/blog/entry/preparing-pyenchant-for-python-3/
try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str, bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring

try:
import simplejson as json
except ImportError:
Expand All @@ -12,7 +29,7 @@


class FluentRecordFormatter(object):
def __init__(self):
def __init__(self, fmt=None, datefmt=None):
self.hostname = socket.gethostname()

def format(self, record):
Expand Down Expand Up @@ -75,4 +92,4 @@ def close(self):
self.sender._close()
logging.Handler.close(self)
finally:
self.release()
self.release()