8000 Configure FluentSender with msgpack.packb() kwargs · delulu/fluent-logger-python@322a89e · GitHub
[go: up one dir, main page]

Skip to content

Commit 322a89e

Browse files
author
Josh Wilson
committed
Configure FluentSender with msgpack.packb() kwargs
This adds an attribute to the `FluentSender` class to enable specialization of the internal call to `msgpack.packb()`. For instance, one can use this provide the `default` parameter to allow for serialization of non-standard types (like `DateTime`).
1 parent 28d38be commit 322a89e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fluent/sender.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self,
5353
verbose=False,
5454
buffer_overflow_handler=None,
5555
nanosecond_precision=False,
56+
msgpack_kwargs=None,
5657
**kwargs): # This kwargs argument is not used in __init__. This will be removed in the next major version.
5758

5859
self.tag = tag
@@ -63,6 +64,7 @@ def __init__(self,
6364
self.verbose = verbose
6465
self.buffer_overflow_handler = buffer_overflow_handler
6566
self.nanosecond_precision = nanosecond_precision
67+
self.msgpack_kwargs = {} if msgpack_kwargs is None else msgpack_kwargs
6668

6769
self.socket = None
6870
self.pendings = None
@@ -109,7 +111,6 @@ def close(self):
109111
finally:
110112
self.lock.release()
111113

112-
113114
def _make_packet(self, label, timestamp, data):
114115
if label:
115116
tag = '.'.join((self.tag, label))
@@ -118,7 +119,7 @@ def _make_packet(self, label, timestamp, data):
118119
packet = (tag, timestamp, data)
119120
if self.verbose:
120121
print(packet)
121-
return msgpack.packb(packet)
122+
return msgpack.packb(packet, **self.msgpack_kwargs)
122123

123124
def _send(self, bytes_):
124125
self.lock.acquire()

0 commit comments

Comments
 (0)
0