Skip to content

Commit

Permalink
Add debug params for log level adjustment in browser (#481)
Browse files Browse the repository at this point in the history
Trying to debug a flash of unstyled content on the website.  Doesn't repro
locally, so want to get some debug output in production.
  • Loading branch information
gigabo authored Aug 2, 2016
1 parent fa140c4 commit 6a65c94
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/react-server/core/ClientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -23,6 +23,8 @@ var _ = {

var RLS = RequestLocalStorage.getNamespace();

var logger = logging.getLogger(__LOGGER__);

// for dev tools
window.React = React;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6a65c94

Please sign in to comment.