diff --git a/.gitignore b/.gitignore index be8621b..fd4bc6c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /.tox /build /dist +.idea/ diff --git a/README.rst b/README.rst index 27607dc..213b6c7 100644 --- a/README.rst +++ b/README.rst @@ -188,7 +188,7 @@ module. logging.basicConfig(level=logging.INFO) l = logging.getLogger('fluent.test') - h = handler.FluentHandler('app.follow', host='host', port=24224) + h = handler.FluentHandler('app.follow', host='host', port=24224, buffer_overflow_handler=handler) formatter = handler.FluentRecordFormatter(custom_format) h.setFormatter(formatter) l.addHandler(h) @@ -211,6 +211,18 @@ You can also customize formatter via logging.config.dictConfig logging.config.dictConfig(conf['logging']) +You can inject your own custom proc to handle buffer overflow in the event of connection failure. This will mitigate the loss of data instead of simply throwing data away. + +.. code:: python + + import msgpack + from io import BytesIO + + def handler(pendings): + unpacker = msgpack.Unpacker(BytesIO(pendings)) + for unpacked in unpacker: + print(unpacked) + A sample configuration ``logging.yaml`` would be: .. code:: python @@ -242,6 +254,7 @@ A sample configuration ``logging.yaml`` would be: host: localhost port: 24224 tag: test.logging + buffer_overflow_handler: handler formatter: fluent_fmt level: DEBUG none: diff --git a/fluent/handler.py b/fluent/handler.py index ef444fd..78eb1d8 100644 --- a/fluent/handler.py +++ b/fluent/handler.py @@ -115,12 +115,14 @@ def __init__(self, host='localhost', port=24224, timeout=3.0, - verbose=False): + verbose=False, + buffer_overflow_handler=None): self.tag = tag self.sender = sender.FluentSender(tag, host=host, port=port, - timeout=timeout, verbose=verbose) + timeout=timeout, verbose=verbose, + buffer_overflow_handler=buffer_overflow_handler) logging.Handler.__init__(self) def emit(self, record):