From 3ab3aa2b40b21b175ad14ca00f8de8b92c60b785 Mon Sep 17 00:00:00 2001 From: Ahmed Refaey Date: Thu, 26 Jan 2017 02:38:08 +0200 Subject: [PATCH 1/2] Enable defining a handler for buffer overflow when using the library as a python logging handler --- .gitignore | 1 + README.rst | 3 ++- fluent/handler.py | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index be8621b..cb43ff3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /.tox /build /dist +/.idea \ No newline at end of file diff --git a/README.rst b/README.rst index 27607dc..04ab3a0 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) @@ -242,6 +242,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): From dcfee053c369be85d9958abc8f47e22587be8dd0 Mon Sep 17 00:00:00 2001 From: Ahmed Refaey Date: Fri, 27 Jan 2017 23:15:18 +0200 Subject: [PATCH 2/2] logging-interface-handle-buffer-overflow Updated the README to include a buffer overflow example --- .gitignore | 2 +- README.rst | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cb43ff3..fd4bc6c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ /.tox /build /dist -/.idea \ No newline at end of file +.idea/ diff --git a/README.rst b/README.rst index 04ab3a0..213b6c7 100644 --- a/README.rst +++ b/README.rst @@ -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