Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Defer print-out of logging in non-development modes

  • Loading branch information...
commit 28d339402679f5a58119fb93e285a27f9f2bde10 1 parent 9c63c8a
@mde mde authored
Showing with 17 additions and 19 deletions.
  1. +14 −16 deps/log.js
  2. +3 −3 lib/cluster/master.js
View
30 deps/log.js
@@ -16,7 +16,7 @@ var color = require('./color');
* @param {Object} stream
* @api public
*/
-var Log = exports = module.exports = function Log(level, stream, print, loggly) {
+var Log = exports = module.exports = function Log(level, stream, printSync) {
if ('string' == typeof level) level = exports[level.toUpperCase()];
this.level = level || exports.DEBUG;
this.stream = stream || process.stdout;
@@ -25,12 +25,7 @@ var Log = exports = module.exports = function Log(level, stream, print, loggly)
this.stream = stream;
this.writing = false;
}
- this.print = print || false;
- if (loggly && typeof loggly.log == 'function') {
- this.loggly = loggly;
- } else {
- this.loggly = false;
- }
+ this.printSync = printSync || false;
if (this.writing && this.stream.readable) this.read(level);
};
/**
@@ -140,17 +135,20 @@ Log.prototype = {
this.stream.write('[' + new Date().toUTCString() + ']' + ' ' + levelStr + ' ' + msg + '\n');
}
- if (this.print) {
- coloredLevelStr = '';
- if (levelStr === 'ERROR') { coloredLevelStr = levelStr.red; }
- if (levelStr === 'WARNING') { coloredLevelStr = levelStr.magenta; }
- if (levelStr === 'NOTICE') { coloredLevelStr = levelStr.green; }
- if (levelStr === 'INFO') { coloredLevelStr = levelStr.blue; }
- if (levelStr === 'DEBUG') { coloredLevelStr = levelStr.yellow; }
+ coloredLevelStr = '';
+ if (levelStr === 'ERROR') { coloredLevelStr = levelStr.red; }
+ if (levelStr === 'WARNING') { coloredLevelStr = levelStr.magenta; }
+ if (levelStr === 'NOTICE') { coloredLevelStr = levelStr.green; }
+ if (levelStr === 'INFO') { coloredLevelStr = levelStr.blue; }
+ if (levelStr === 'DEBUG') { coloredLevelStr = levelStr.yellow; }
+ // HACK: defer printing in non-developement modes
+ if (this.printSync) {
console.log(('[' + new Date().toUTCString() + ']').cyan + ' ' + coloredLevelStr + ' ' + msg);
}
- if (typeof this.loggly.log == 'function' && (this.loggly.logLevel >= exports[levelStr])) {
- this.loggly.log({eventType: levelStr, message: msg});
+ else {
+ setTimeout(function () {
+ console.log(('[' + new Date().toUTCString() + ']').cyan + ' ' + coloredLevelStr + ' ' + msg);
+ }, 0);
}
} else if (levelStr == 'ACCESS') {
if (this.writing) {
View
6 lib/cluster/master.js
@@ -47,7 +47,7 @@ Master.prototype = new (function () {
, dir = this.config.logDir
, levelsByType = {access: 'access', stderr: 'error', stdout: 0}
, writing = dir != null
- , loggly
+ , printSync = this.config.environment == 'development'
, rotateAndInitByType;
// Colon is not valid filepath char in Win
@@ -97,10 +97,10 @@ Master.prototype = new (function () {
// e.g., stdoutLog
if (writing) {
self[type + 'Log'] = new Log(levelsByType[type],
- fs.createWriteStream(currentLog), true, loggly);
+ fs.createWriteStream(currentLog), printSync);
}
else {
- self[type + 'Log'] = new Log(levelsByType[type], null, true, loggly);
+ self[type + 'Log'] = new Log(levelsByType[type], null, printSync);
}
self[type + 'Log'].type = type;
Please sign in to comment.
Something went wrong with that request. Please try again.