Skip to content

Commit

Permalink
Add silence routes logging to dev tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Sep 21, 2018
1 parent 9a07168 commit a47c5d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dash/_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def env_configs():
'DASH_DEBUG',
'DASH_HOT_RELOAD',
'DASH_HOT_RELOAD_INTERVAL',
'DASH_HOT_RELOAD_WATCH_INTERVAL'
'DASH_HOT_RELOAD_WATCH_INTERVAL',
'DASH_SILENCE_ROUTES_LOGGING'
)})


Expand Down
35 changes: 33 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import threading
import warnings
import re
import logging

from functools import wraps

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

self.logger = logging.getLogger(name)
self.logger.addHandler(logging.StreamHandler(stream=sys.stdout))

@property
def layout(self):
return self._layout
Expand Down Expand Up @@ -1029,7 +1033,9 @@ def enable_dev_tools(self,
dev_tools_serve_dev_bundles=None,
dev_tools_hot_reload=None,
dev_tools_hot_reload_interval=None,
dev_tools_hot_reload_watch_interval=None):
dev_tools_hot_reload_watch_interval=None,
dev_tools_silence_routes_logging=None,
):
"""
Activate the dev tools, called by `run_server`. If your application is
served by wsgi and you want to activate the dev tools, you can call
Expand Down Expand Up @@ -1057,6 +1063,9 @@ def enable_dev_tools(self,
assets folder are walked for changes. Available as
`DASH_HOT_RELOAD_WATCH_INTERVAL` environ var.
:type dev_tools_hot_reload_watch_interval: float
:param dev_tools_silence_routes_logging: Silence the `werkzeug` logger,
will remove all routes logging.
:type dev_tools_silence_routes_logging: bool
:return: debug
"""
env = _configs.env_configs()
Expand Down Expand Up @@ -1085,6 +1094,15 @@ def enable_dev_tools(self,
default=0.5
)
)
self._dev_tools['silence_routes_logging'] = _configs.get_config(
'silence_routes_logging', dev_tools_silence_routes_logging, env,
default=debug,
is_bool=True,
)

if self._dev_tools.silence_routes_logging:
logging.getLogger('werkzeug').setLevel(logging.ERROR)
self.logger.setLevel(logging.INFO)

if self._dev_tools.hot_reload:
self._reload_hash = _generate_hash()
Expand Down Expand Up @@ -1154,6 +1172,7 @@ def run_server(self,
dev_tools_hot_reload=None,
dev_tools_hot_reload_interval=None,
dev_tools_hot_reload_watch_interval=None,
dev_tools_silence_routes_logging=None,
**flask_run_options):
"""
Start the flask server in local mode, you should not run this on a
Expand All @@ -1179,7 +1198,19 @@ def run_server(self,
dev_tools_serve_dev_bundles,
dev_tools_hot_reload,
dev_tools_hot_reload_interval,
dev_tools_hot_reload_watch_interval
dev_tools_hot_reload_watch_interval,
dev_tools_silence_routes_logging
)

if self._dev_tools.silence_routes_logging:
# Since it's silenced, the address don't show anymore.
host = flask_run_options.get('host', '127.0.0.1')
ssl_context = flask_run_options.get('ssl_context')
self.logger.info(
'Running on {}://{}:{}{}'.format(
'https' if ssl_context else 'http',
host, port, self.config.requests_pathname_prefix)
)

self.server.run(port=port, debug=debug,
**flask_run_options)

0 comments on commit a47c5d7

Please sign in to comment.