Skip to content

Commit f99565f

Browse files
authored
Merge pull request #2425 from plotly/logging-fix
Move logger to dash namespace, add stream handler once.
2 parents ae71e86 + 589c2bb commit f99565f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ This project adheres to [Semantic Versioning](https://semver.org/).
88

99
- [#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)
1010
- [#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)
11+
- [#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.
1112

1213
## Fixed
1314

1415
- [#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).
1516
- [#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.
17+
- [#2425](https://github.com/plotly/dash/pull/2425) Fix multiple log handler added unconditionally to the logger, resulting in duplicate log message.
18+
19+
## Changed
20+
21+
- [#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.
1622

1723
## [UNRELEASED]
1824

dash/dash.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ class Dash:
329329
:param background_callback_manager: Background callback manager instance
330330
to support the ``@callback(..., background=True)`` decorator.
331331
One of ``DiskcacheManager`` or ``CeleryManager`` currently supported.
332+
333+
:param add_log_handler: Automatically add a StreamHandler to the app logger
334+
if not added previously.
332335
"""
333336

334337
def __init__( # pylint: disable=too-many-statements
@@ -361,6 +364,7 @@ def __init__( # pylint: disable=too-many-statements
361364
update_title="Updating...",
362365
long_callback_manager=None,
363366
background_callback_manager=None,
367+
add_log_handler=True,
364368
**obsolete,
365369
):
366370
_validate.check_obsolete(obsolete)
@@ -481,8 +485,10 @@ def __init__( # pylint: disable=too-many-statements
481485
self._long_callback_count = 0
482486
self._background_manager = background_callback_manager or long_callback_manager
483487

484-
self.logger = logging.getLogger(name)
485-
self.logger.addHandler(logging.StreamHandler(stream=sys.stdout))
488+
self.logger = logging.getLogger(__name__)
489+
490+
if not self.logger.handlers and add_log_handler:
491+
self.logger.addHandler(logging.StreamHandler(stream=sys.stdout))
486492

487493
if isinstance(plugins, patch_collections_abc("Iterable")):
488494
for plugin in plugins:

0 commit comments

Comments
 (0)