Skip to content

Commit a47c5d7

Browse files
committed
Add silence routes logging to dev tools.
1 parent 9a07168 commit a47c5d7

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

dash/_configs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def env_configs():
2525
'DASH_DEBUG',
2626
'DASH_HOT_RELOAD',
2727
'DASH_HOT_RELOAD_INTERVAL',
28-
'DASH_HOT_RELOAD_WATCH_INTERVAL'
28+
'DASH_HOT_RELOAD_WATCH_INTERVAL',
29+
'DASH_SILENCE_ROUTES_LOGGING'
2930
)})
3031

3132

dash/dash.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import threading
1010
import warnings
1111
import re
12+
import logging
1213

1314
from functools import wraps
1415

@@ -247,6 +248,9 @@ def add_url(name, view_func, methods=('GET',)):
247248
self._watch_thread = None
248249
self._changed_assets = []
249250

251+
self.logger = logging.getLogger(name)
252+
self.logger.addHandler(logging.StreamHandler(stream=sys.stdout))
253+
250254
@property
251255
def layout(self):
252256
return self._layout
@@ -1029,7 +1033,9 @@ def enable_dev_tools(self,
10291033
dev_tools_serve_dev_bundles=None,
10301034
dev_tools_hot_reload=None,
10311035
dev_tools_hot_reload_interval=None,
1032-
dev_tools_hot_reload_watch_interval=None):
1036+
dev_tools_hot_reload_watch_interval=None,
1037+
dev_tools_silence_routes_logging=None,
1038+
):
10331039
"""
10341040
Activate the dev tools, called by `run_server`. If your application is
10351041
served by wsgi and you want to activate the dev tools, you can call
@@ -1057,6 +1063,9 @@ def enable_dev_tools(self,
10571063
assets folder are walked for changes. Available as
10581064
`DASH_HOT_RELOAD_WATCH_INTERVAL` environ var.
10591065
:type dev_tools_hot_reload_watch_interval: float
1066+
:param dev_tools_silence_routes_logging: Silence the `werkzeug` logger,
1067+
will remove all routes logging.
1068+
:type dev_tools_silence_routes_logging: bool
10601069
:return: debug
10611070
"""
10621071
env = _configs.env_configs()
@@ -1085,6 +1094,15 @@ def enable_dev_tools(self,
10851094
default=0.5
10861095
)
10871096
)
1097+
self._dev_tools['silence_routes_logging'] = _configs.get_config(
1098+
'silence_routes_logging', dev_tools_silence_routes_logging, env,
1099+
default=debug,
1100+
is_bool=True,
1101+
)
1102+
1103+
if self._dev_tools.silence_routes_logging:
1104+
logging.getLogger('werkzeug').setLevel(logging.ERROR)
1105+
self.logger.setLevel(logging.INFO)
10881106

10891107
if self._dev_tools.hot_reload:
10901108
self._reload_hash = _generate_hash()
@@ -1154,6 +1172,7 @@ def run_server(self,
11541172
dev_tools_hot_reload=None,
11551173
dev_tools_hot_reload_interval=None,
11561174
dev_tools_hot_reload_watch_interval=None,
1175+
dev_tools_silence_routes_logging=None,
11571176
**flask_run_options):
11581177
"""
11591178
Start the flask server in local mode, you should not run this on a
@@ -1179,7 +1198,19 @@ def run_server(self,
11791198
dev_tools_serve_dev_bundles,
11801199
dev_tools_hot_reload,
11811200
dev_tools_hot_reload_interval,
1182-
dev_tools_hot_reload_watch_interval
1201+
dev_tools_hot_reload_watch_interval,
1202+
dev_tools_silence_routes_logging
11831203
)
1204+
1205+
if self._dev_tools.silence_routes_logging:
1206+
# Since it's silenced, the address don't show anymore.
1207+
host = flask_run_options.get('host', '127.0.0.1')
1208+
ssl_context = flask_run_options.get('ssl_context')
1209+
self.logger.info(
1210+
'Running on {}://{}:{}{}'.format(
1211+
'https' if ssl_context else 'http',
1212+
host, port, self.config.requests_pathname_prefix)
1213+
)
1214+
11841215
self.server.run(port=port, debug=debug,
11851216
**flask_run_options)

0 commit comments

Comments
 (0)