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] diff --git a/dash/dash.py b/dash/dash.py index c9fce8d129..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) @@ -481,8 +485,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 and add_log_handler: + self.logger.addHandler(logging.StreamHandler(stream=sys.stdout)) if isinstance(plugins, patch_collections_abc("Iterable")): for plugin in plugins: