Skip to content

Commit

Permalink
Don’t create any tuples or push them to the queue if log() is not
Browse files Browse the repository at this point in the history
called within the context of a request.
  • Loading branch information
Vincent Chang committed Aug 26, 2016
1 parent b7346f7 commit a3170c9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/react-server/core/logging/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ var queue = () => {
}
}

var pushToQueue = (tuple) => {
var pushToQueue = (module, lastModuleToken, key, level, msg, meta) => {
if (RLS.isActive() && !!RLS().doLog) {
var tuple = [
module,
msg,
meta[key],
lastModuleToken,
];
queue().push(tuple);
}
}
Expand All @@ -28,13 +34,7 @@ class ResponseLogger extends SuperLogger {
}

log(level, msg, meta, callback) {
var tuple = [
this.module,
msg,
meta[this.key],
this.lastModuleToken,
];
pushToQueue(tuple);
pushToQueue(this.module, this.lastModuleToken, this.key, level, msg, meta);
// Yield to the next log transport.
callback(null, true);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ var getTransportForGroup = function(group, opts) {
}
}

var flushLogsToResponse = function(res) {
var flushLogsToResponse = function(res) {
if (queue().length > 0) {
res.write("<script>");
res.write(`window.reactServerLogs = ${JSON.stringify(queue())};\n`);
Expand All @@ -79,7 +79,7 @@ var flushLogsToResponse = function(res) {
}

var setResponseLoggerPage = function(page) {
if (RLS.isActive() || !!page) {
if (RLS.isActive() && !!page) {
RLS().doLog = page.getRequest().getQuery()._debug_output_logs;
}
}
Expand Down

0 comments on commit a3170c9

Please sign in to comment.