From b40c6e8950daf32161f1f4d6082e70d419ff16e0 Mon Sep 17 00:00:00 2001 From: Bo Borgerson Date: Mon, 1 Aug 2016 11:10:59 -0700 Subject: [PATCH] Add debug params for log level adjustment in browser Trying to debug a flash of unstyled content on the website. Doesn't repro locally, so want to get some debug output in production. --- .../react-server/core/ClientController.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-server/core/ClientController.js b/packages/react-server/core/ClientController.js index 138c24be7..dd0c71529 100644 --- a/packages/react-server/core/ClientController.js +++ b/packages/react-server/core/ClientController.js @@ -2,7 +2,7 @@ var React = require('react'), ReactDOM = require('react-dom'), MobileDetect = require('mobile-detect'), - logger = require('./logging').getLogger(__LOGGER__), + logging = require('./logging'), RequestContext = require('./context/RequestContext'), RequestLocalStorage = require('./util/RequestLocalStorage'), Q = require('q'), @@ -23,6 +23,8 @@ var _ = { var RLS = RequestLocalStorage.getNamespace(); +var logger = logging.getLogger(__LOGGER__); + // for dev tools window.React = React; @@ -340,6 +342,8 @@ class ClientController extends EventEmitter { context.onNavigate( (err, page) => { logger.debug('Executing navigate action'); + this._handleDebugParams(page); + if (err) { // redirects are sent as errors, so let's handle it if that's the case. if (err.status && (err.status === 301 || err.status === 302)) { @@ -414,6 +418,22 @@ class ClientController extends EventEmitter { } + _handleDebugParams(page) { + const params = page.getRequest().getQuery(); + + // Allow adjustment of log levels. + _.forEach({ + _react_server_log_level : 'main', + _react_server_log_level_main : 'main', + _react_server_log_level_time : 'time', + _react_server_log_level_gauge : 'gauge', + }, (type, param) => { + if (params[param]) { + logging.setLevel(type, params[param]); + } + }); + } + _renderTitle(page) { page.getTitle().then(newTitle => { if (newTitle && newTitle !== document.title) {