From 5d722b94d768eb99768049270efba6d2dc7d22ed Mon Sep 17 00:00:00 2001 From: philippe Date: Tue, 14 Feb 2023 15:09:55 -0500 Subject: [PATCH 1/3] Move logger to dash namespace, add stream handler once. --- dash/dash.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index c9fce8d129..a1cdbc6ae1 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -481,8 +481,10 @@ def __init__( # pylint: disable=too-many-statements self._long_callback_count = 0 self._background_manager = background_callback_manager or long_callback_manager - self.logger = logging.getLogger(name) - self.logger.addHandler(logging.StreamHandler(stream=sys.stdout)) + self.logger = logging.getLogger(__name__) + + if not self.logger.handlers: + self.logger.addHandler(logging.StreamHandler(stream=sys.stdout)) if isinstance(plugins, patch_collections_abc("Iterable")): for plugin in plugins: From 4ed43e8db388d48dcd1a3f0856d1fe7db60f7f46 Mon Sep 17 00:00:00 2001 From: philippe Date: Tue, 14 Feb 2023 15:16:03 -0500 Subject: [PATCH 2/3] Add add_log_handler argument to Dash init. --- dash/dash.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index a1cdbc6ae1..1bac15ab97 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -329,6 +329,9 @@ class Dash: :param background_callback_manager: Background callback manager instance to support the ``@callback(..., background=True)`` decorator. One of ``DiskcacheManager`` or ``CeleryManager`` currently supported. + + :param add_log_handler: Automatically add a StreamHandler to the app logger + if not added previously. """ def __init__( # pylint: disable=too-many-statements @@ -361,6 +364,7 @@ def __init__( # pylint: disable=too-many-statements update_title="Updating...", long_callback_manager=None, background_callback_manager=None, + add_log_handler=True, **obsolete, ): _validate.check_obsolete(obsolete) @@ -483,7 +487,7 @@ def __init__( # pylint: disable=too-many-statements self.logger = logging.getLogger(__name__) - if not self.logger.handlers: + if not self.logger.handlers and add_log_handler: self.logger.addHandler(logging.StreamHandler(stream=sys.stdout)) if isinstance(plugins, patch_collections_abc("Iterable")): From 589c2bb92d874cdbf17fc52782396b24a1faaaab Mon Sep 17 00:00:00 2001 From: philippe Date: Wed, 15 Feb 2023 11:39:57 -0500 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64c6d059b6..ab1c89124d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,17 @@ This project adheres to [Semantic Versioning](https://semver.org/). - [#2417](https://github.com/plotly/dash/pull/2417) Add wait_timeout property to customize the behavior of the default wait timeout used for by wait_for_page, fix [#1595](https://github.com/plotly/dash/issues/1595) - [#2417](https://github.com/plotly/dash/pull/2417) Add the element target text for wait_for_text* error message, fix [#945](https://github.com/plotly/dash/issues/945) +- [#2425](https://github.com/plotly/dash/pull/2425) Add `add_log_handler=True` to Dash init, if you don't want a log stream handler at all. ## Fixed - [#2417](https://github.com/plotly/dash/pull/2417) Disable the pytest plugin if `dash[testing]` not installed, fix [#946](https://github.com/plotly/dash/issues/946). - [#2417](https://github.com/plotly/dash/pull/2417) Do not swallow the original error to get the webdriver, easier to know what is wrong after updating the browser but the driver. +- [#2425](https://github.com/plotly/dash/pull/2425) Fix multiple log handler added unconditionally to the logger, resulting in duplicate log message. + +## Changed + +- [#2425](https://github.com/plotly/dash/pull/2425) Moved the logger namespace to `dash.dash`, as library logger it should be on that namespace instead of the user app. ## [UNRELEASED]