replaced my debug lib with standard one
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = function(label) {
|
|
||||||
var debug;
|
|
||||||
|
|
||||||
if (process.env.NODE_DEBUG && /\blog4js\b/.test(process.env.NODE_DEBUG)) {
|
|
||||||
debug = function(message) {
|
|
||||||
console.error('LOG4JS: (%s) %s', label, message);
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
debug = function() { };
|
|
||||||
}
|
|
||||||
|
|
||||||
return debug;
|
|
||||||
};
|
|
||||||
+14
-7
@@ -46,7 +46,7 @@
|
|||||||
* @static
|
* @static
|
||||||
* Website: http://log4js.berlios.de
|
* Website: http://log4js.berlios.de
|
||||||
*/
|
*/
|
||||||
var debug = require('./debug')('core')
|
var debug = require('debug')('log4js:core')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, cluster = require('cluster')
|
, cluster = require('cluster')
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
@@ -90,10 +90,10 @@ function deserialise(serialised) {
|
|||||||
//in a multi-process node environment, worker loggers will use
|
//in a multi-process node environment, worker loggers will use
|
||||||
//process.send
|
//process.send
|
||||||
cluster.on('fork', function(worker) {
|
cluster.on('fork', function(worker) {
|
||||||
debug('listening to worker: ' + worker);
|
debug('listening to worker: ', worker);
|
||||||
worker.on('message', function(message) {
|
worker.on('message', function(message) {
|
||||||
if (message.type && message.type === '::log4js-message') {
|
if (message.type && message.type === '::log4js-message') {
|
||||||
debug("received message: " + message.event);
|
debug("received message: ", message.event);
|
||||||
dispatch(deserialise(message.event));
|
dispatch(deserialise(message.event));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -106,7 +106,7 @@ cluster.on('fork', function(worker) {
|
|||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function getLogger (category) {
|
function getLogger (category) {
|
||||||
debug("getLogger(" + category + ")");
|
debug("getLogger(", category, ")");
|
||||||
|
|
||||||
return new Logger(
|
return new Logger(
|
||||||
cluster.isMaster ? dispatch : workerDispatch,
|
cluster.isMaster ? dispatch : workerDispatch,
|
||||||
@@ -123,9 +123,9 @@ function workerDispatch(event) {
|
|||||||
* This would be a good place to implement category hierarchies/wildcards, etc
|
* This would be a good place to implement category hierarchies/wildcards, etc
|
||||||
*/
|
*/
|
||||||
function dispatch(event) {
|
function dispatch(event) {
|
||||||
debug("event is " + util.inspect(event));
|
debug("event is ", event);
|
||||||
var category = categories[event.category] || categories.default;
|
var category = categories[event.category] || categories.default;
|
||||||
debug("category.level[" + category.level + "] <= " + event.level + " ? " + category.level.isLessThanOrEqualTo(event.level));
|
debug("category.level[", category.level, "] <= ", event.level, " ? ", category.level.isLessThanOrEqualTo(event.level));
|
||||||
|
|
||||||
if (category.level.isLessThanOrEqualTo(event.level)) {
|
if (category.level.isLessThanOrEqualTo(event.level)) {
|
||||||
category.appenders.forEach(function(appender) {
|
category.appenders.forEach(function(appender) {
|
||||||
@@ -135,17 +135,24 @@ function dispatch(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load(file) {
|
function load(file) {
|
||||||
|
debug("loading ", file);
|
||||||
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(configurationFileOrObject) {
|
function configure(configurationFileOrObject) {
|
||||||
var filename, config = configurationFileOrObject || process.env.LOG4JS_CONFIG;
|
debug("configure(", configurationFileOrObject, ")");
|
||||||
|
debug("process.env.LOG4JS_CONFIG = ", process.env.LOG4JS_CONFIG);
|
||||||
|
|
||||||
|
var filename, config = process.env.LOG4JS_CONFIG || configurationFileOrObject;
|
||||||
|
|
||||||
|
debug("config ", config);
|
||||||
|
|
||||||
if (!config || !(typeof config === 'string' || typeof config === 'object')) {
|
if (!config || !(typeof config === 'string' || typeof config === 'object')) {
|
||||||
throw new Error("You must specify configuration as an object or a filename.");
|
throw new Error("You must specify configuration as an object or a filename.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
|
debug("config is string");
|
||||||
filename = config;
|
filename = config;
|
||||||
config = load(filename);
|
config = load(filename);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -1,7 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var debug = require('./debug')('logger')
|
var debug = require('debug')('log4js:logger')
|
||||||
, levels = require('./levels')
|
, levels = require('./levels');
|
||||||
, util = require('util');
|
|
||||||
|
|
||||||
module.exports = function Logger(dispatch, category) {
|
module.exports = function Logger(dispatch, category) {
|
||||||
if (typeof dispatch !== 'function') {
|
if (typeof dispatch !== 'function') {
|
||||||
@@ -16,7 +15,7 @@ module.exports = function Logger(dispatch, category) {
|
|||||||
var args = Array.prototype.slice.call(arguments)
|
var args = Array.prototype.slice.call(arguments)
|
||||||
, logLevel = args.shift()
|
, logLevel = args.shift()
|
||||||
, loggingEvent = new LoggingEvent(category, logLevel, args);
|
, loggingEvent = new LoggingEvent(category, logLevel, args);
|
||||||
debug("Logging event " + loggingEvent + " to dispatch = " + util.inspect(dispatch));
|
debug("Logging event ", loggingEvent, " to dispatch = ", dispatch);
|
||||||
dispatch(loggingEvent);
|
dispatch(loggingEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
, stream
|
, stream
|
||||||
, debug = require('../debug')('BaseRollingFileStream')
|
, debug = require('debug')('log4js:BaseRollingFileStream')
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
, semver = require('semver');
|
, semver = require('semver');
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||||
, debug = require('../debug')('DateRollingFileStream')
|
, debug = require('debug')('log4js:DateRollingFileStream')
|
||||||
, format = require('../date_format')
|
, format = require('../date_format')
|
||||||
, async = require('async')
|
, async = require('async')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
@@ -9,7 +9,7 @@ var BaseRollingFileStream = require('./BaseRollingFileStream')
|
|||||||
module.exports = DateRollingFileStream;
|
module.exports = DateRollingFileStream;
|
||||||
|
|
||||||
function DateRollingFileStream(filename, pattern, options, now) {
|
function DateRollingFileStream(filename, pattern, options, now) {
|
||||||
debug("Now is " + now);
|
debug("Now is ", now);
|
||||||
if (pattern && typeof(pattern) === 'object') {
|
if (pattern && typeof(pattern) === 'object') {
|
||||||
now = options;
|
now = options;
|
||||||
options = pattern;
|
options = pattern;
|
||||||
@@ -31,7 +31,7 @@ function DateRollingFileStream(filename, pattern, options, now) {
|
|||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug("this.now is " + this.now + ", now is " + now);
|
debug("this.now is ", this.now, ", now is ", now);
|
||||||
|
|
||||||
DateRollingFileStream.super_.call(this, filename, options);
|
DateRollingFileStream.super_.call(this, filename, options);
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,8 @@ DateRollingFileStream.prototype.shouldRoll = function() {
|
|||||||
var lastTime = this.lastTimeWeWroteSomething,
|
var lastTime = this.lastTimeWeWroteSomething,
|
||||||
thisTime = format.asString(this.pattern, new Date(this.now()));
|
thisTime = format.asString(this.pattern, new Date(this.now()));
|
||||||
|
|
||||||
debug("DateRollingFileStream.shouldRoll with now = " +
|
debug("DateRollingFileStream.shouldRoll with now = ",
|
||||||
this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
|
this.now(), ", thisTime = ", thisTime, ", lastTime = ", lastTime);
|
||||||
|
|
||||||
this.lastTimeWeWroteSomething = thisTime;
|
this.lastTimeWeWroteSomething = thisTime;
|
||||||
this.previousTime = lastTime;
|
this.previousTime = lastTime;
|
||||||
@@ -81,7 +81,7 @@ DateRollingFileStream.prototype.roll = function(filename, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renameTheCurrentFile(cb) {
|
function renameTheCurrentFile(cb) {
|
||||||
debug("Renaming the " + filename + " -> " + newFilename);
|
debug("Renaming the ", filename, " -> ", newFilename);
|
||||||
fs.rename(filename, newFilename, cb);
|
fs.rename(filename, newFilename, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||||
, debug = require('../debug')('RollingFileStream')
|
, debug = require('debug')('log4js:RollingFileStream')
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
@@ -53,13 +53,13 @@ RollingFileStream.prototype.roll = function(filename, callback) {
|
|||||||
|
|
||||||
function increaseFileIndex (fileToRename, cb) {
|
function increaseFileIndex (fileToRename, cb) {
|
||||||
var idx = index(fileToRename);
|
var idx = index(fileToRename);
|
||||||
debug('Index of ' + fileToRename + ' is ' + idx);
|
debug('Index of ', fileToRename, ' is ', idx);
|
||||||
if (idx < that.backups) {
|
if (idx < that.backups) {
|
||||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
||||||
//so, we'll try to delete the file we're renaming to first
|
//so, we'll try to delete the file we're renaming to first
|
||||||
fs.unlink(filename + '.' + (idx+1), function (err) {
|
fs.unlink(filename + '.' + (idx+1), function (err) {
|
||||||
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
||||||
debug('Renaming ' + fileToRename + ' -> ' + filename + '.' + (idx+1));
|
debug('Renaming ', fileToRename, ' -> ', filename, '.', (idx+1));
|
||||||
fs.rename(path.join(path.dirname(filename), fileToRename), filename + '.' + (idx + 1), cb);
|
fs.rename(path.join(path.dirname(filename), fileToRename), filename + '.' + (idx + 1), cb);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-1
@@ -30,7 +30,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "0.1.15",
|
"async": "0.1.15",
|
||||||
"semver": "~1.1.4",
|
"semver": "~1.1.4",
|
||||||
"readable-stream": "~1.0.2"
|
"readable-stream": "~1.0.2",
|
||||||
|
"debug": "~0.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sandboxed-module": "0.1.3",
|
"sandboxed-module": "0.1.3",
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var vows = require('vows')
|
|
||||||
, assert = require('assert')
|
|
||||||
, sandbox = require('sandboxed-module')
|
|
||||||
, fakeConsole = {
|
|
||||||
error: function(format, label, message) {
|
|
||||||
this.logged = [ format, label, message ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, globals = function(debugValue) {
|
|
||||||
return {
|
|
||||||
process: {
|
|
||||||
env: {
|
|
||||||
'NODE_DEBUG': debugValue
|
|
||||||
}
|
|
||||||
},
|
|
||||||
console: fakeConsole
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vows.describe('../lib/debug').addBatch({
|
|
||||||
'when NODE_DEBUG is set to log4js': {
|
|
||||||
topic: function() {
|
|
||||||
var debug = sandbox.require(
|
|
||||||
'../lib/debug',
|
|
||||||
{ 'globals': globals('log4js') }
|
|
||||||
);
|
|
||||||
|
|
||||||
fakeConsole.logged = [];
|
|
||||||
debug('cheese')('biscuits');
|
|
||||||
return fakeConsole.logged;
|
|
||||||
},
|
|
||||||
'it should log to console.error': function(logged) {
|
|
||||||
assert.equal(logged[0], 'LOG4JS: (%s) %s');
|
|
||||||
assert.equal(logged[1], 'cheese');
|
|
||||||
assert.equal(logged[2], 'biscuits');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'when NODE_DEBUG is set to not log4js': {
|
|
||||||
topic: function() {
|
|
||||||
var debug = sandbox.require(
|
|
||||||
'../lib/debug',
|
|
||||||
{ globals: globals('other_module') }
|
|
||||||
);
|
|
||||||
|
|
||||||
fakeConsole.logged = [];
|
|
||||||
debug('cheese')('biscuits');
|
|
||||||
return fakeConsole.logged;
|
|
||||||
},
|
|
||||||
'it should not log to console.error': function(logged) {
|
|
||||||
assert.equal(logged.length, 0);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'when NODE_DEBUG is not set': {
|
|
||||||
topic: function() {
|
|
||||||
var debug = sandbox.require(
|
|
||||||
'../lib/debug',
|
|
||||||
{ globals: globals(null) }
|
|
||||||
);
|
|
||||||
|
|
||||||
fakeConsole.logged = [];
|
|
||||||
debug('cheese')('biscuits');
|
|
||||||
return fakeConsole.logged;
|
|
||||||
},
|
|
||||||
'it should not log to console.error': function(logged) {
|
|
||||||
assert.equal(logged.length, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}).exportTo(module);
|
|
||||||
+1
-2
@@ -39,7 +39,7 @@ describe('../lib/log4js', function() {
|
|||||||
(function() { log4js.configure(); }).should.throw(
|
(function() { log4js.configure(); }).should.throw(
|
||||||
"ENOENT, no such file or directory 'made-up-file'"
|
"ENOENT, no such file or directory 'made-up-file'"
|
||||||
);
|
);
|
||||||
process.env.LOG4JS_CONFIG = null;
|
delete process.env.LOG4JS_CONFIG;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should complain if the config does not specify any appenders', function() {
|
it('should complain if the config does not specify any appenders', function() {
|
||||||
@@ -286,7 +286,6 @@ describe('../lib/log4js', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload configuration if specified');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with no configuration', function() {
|
describe('with no configuration', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user