From 7d665cf34a8504e1b5573ed4b5d921a355b507b3 Mon Sep 17 00:00:00 2001 From: Derrick Gilland Date: Thu, 22 Jan 2015 21:28:07 -0500 Subject: [PATCH] Move handler and listener default classes to class attributes. --- flask_logconfig/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/flask_logconfig/__init__.py b/flask_logconfig/__init__.py index 94ce989..c7c7800 100644 --- a/flask_logconfig/__init__.py +++ b/flask_logconfig/__init__.py @@ -31,12 +31,17 @@ class LogConfig(object): """Flask extension for configuring Python's logging module from application's config object. """ + default_handler_class = FlaskQueueHandler + default_listener_class = logconfig.QueueListener + def __init__(self, app=None, start_listeners=True, - handler_class=FlaskQueueHandler, - listener_class=logconfig.QueueListener): + handler_class=None, + listener_class=None): self.app = app + self.handler_class = handler_class + self.listener_class = listener_class self.listeners = {} if app is not None: # pragma: no cover @@ -45,12 +50,18 @@ def __init__(self, def init_app(self, app, start_listeners=True, - handler_class=FlaskQueueHandler, - listener_class=logconfig.QueueListener): + handler_class=None, + listener_class=None): """Initialize extension on Flask application.""" app.config.setdefault('LOGGING', None) app.config.setdefault('LOGGING_QUEUE', []) + handler_class = (handler_class if handler_class is not None + else self.default_handler_class) + + listener_class = (listener_class if listener_class is not None + else self.default_listener_class) + if app.config['LOGGING']: # NOTE: app.logger clears all attached loggers from # app.config['LOGGER_NAME'] but ONLY AFTER FIRST ACCESS! Therefore,