Skip to content

Commit

Permalink
Merge pull request #1355 from anders-kiaer/dash_logger
Browse files Browse the repository at this point in the history
Move Dash logger.setLevel to init + remove now redundant startup message
  • Loading branch information
alexcjohnson committed Aug 5, 2020
2 parents f195f8a + 2cfe07c commit 44a45fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]
### Added
- [#1355](https://github.com/plotly/dash/pull/1355) Removed redundant log message and consolidated logger initialization. You can now control the log level - for example suppress informational messages from Dash with `app.logger.setLevel(logging.WARNING)`.

## [1.14.0] - 2020-07-27
### Added
- [#1343](https://github.com/plotly/dash/pull/1343) Add `title` parameter to set the
Expand Down
10 changes: 2 additions & 8 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def __init__(
if self.server is not None:
self.init_app()

self.logger.setLevel(logging.INFO)

def init_app(self, app=None):
"""Initialize the parts of Dash that require a flask app."""
config = self.config
Expand Down Expand Up @@ -1351,8 +1353,6 @@ def enable_dev_tools(
if dev_tools.silence_routes_logging:
logging.getLogger("werkzeug").setLevel(logging.ERROR)

self.logger.setLevel(logging.INFO)

if dev_tools.hot_reload:
_reload = self._hot_reload
_reload.hash = generate_hash()
Expand Down Expand Up @@ -1624,11 +1624,5 @@ def verify_url_part(served_part, url_part, part_name):
display_url = (protocol, host, ":{}".format(port), path)

self.logger.info("Dash is running on %s://%s%s%s\n", *display_url)
self.logger.info(
" Warning: This is a development server. Do not use app.run_server"
)
self.logger.info(
" in production, use a production WSGI server like gunicorn instead.\n"
)

self.server.run(host=host, port=port, debug=debug, **flask_run_options)
15 changes: 13 additions & 2 deletions tests/unit/test_configs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import logging

import pytest
from flask import Flask
Expand Down Expand Up @@ -256,15 +257,25 @@ def test_port_env_fail_range(empty_environ):
)


def test_no_proxy_success(mocker, caplog, empty_environ):
@pytest.mark.parametrize(
"setlevel_warning", [False, True],
)
def test_no_proxy_success(mocker, caplog, empty_environ, setlevel_warning):
app = Dash()

if setlevel_warning:
app.logger.setLevel(logging.WARNING)

# mock out the run method so we don't actually start listening forever
mocker.patch.object(app.server, "run")

app.run_server(port=8787)

assert "Dash is running on http://127.0.0.1:8787/\n" in caplog.text
STARTUP_MESSAGE = "Dash is running on http://127.0.0.1:8787/\n"
if setlevel_warning:
assert caplog.text is None or STARTUP_MESSAGE not in caplog.text
else:
assert STARTUP_MESSAGE in caplog.text


@pytest.mark.parametrize(
Expand Down

0 comments on commit 44a45fc

Please sign in to comment.