replaced my debug lib with standard one
This commit is contained in:
15
lib/debug.js
15
lib/debug.js
@@ -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;
|
||||
};
|
||||
@@ -46,7 +46,7 @@
|
||||
* @static
|
||||
* Website: http://log4js.berlios.de
|
||||
*/
|
||||
var debug = require('./debug')('core')
|
||||
var debug = require('debug')('log4js:core')
|
||||
, fs = require('fs')
|
||||
, cluster = require('cluster')
|
||||
, util = require('util')
|
||||
@@ -90,10 +90,10 @@ function deserialise(serialised) {
|
||||
//in a multi-process node environment, worker loggers will use
|
||||
//process.send
|
||||
cluster.on('fork', function(worker) {
|
||||
debug('listening to worker: ' + worker);
|
||||
debug('listening to worker: ', worker);
|
||||
worker.on('message', function(message) {
|
||||
if (message.type && message.type === '::log4js-message') {
|
||||
debug("received message: " + message.event);
|
||||
debug("received message: ", message.event);
|
||||
dispatch(deserialise(message.event));
|
||||
}
|
||||
});
|
||||
@@ -106,7 +106,7 @@ cluster.on('fork', function(worker) {
|
||||
* @static
|
||||
*/
|
||||
function getLogger (category) {
|
||||
debug("getLogger(" + category + ")");
|
||||
debug("getLogger(", category, ")");
|
||||
|
||||
return new Logger(
|
||||
cluster.isMaster ? dispatch : workerDispatch,
|
||||
@@ -123,9 +123,9 @@ function workerDispatch(event) {
|
||||
* This would be a good place to implement category hierarchies/wildcards, etc
|
||||
*/
|
||||
function dispatch(event) {
|
||||
debug("event is " + util.inspect(event));
|
||||
debug("event is ", event);
|
||||
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)) {
|
||||
category.appenders.forEach(function(appender) {
|
||||
@@ -135,17 +135,24 @@ function dispatch(event) {
|
||||
}
|
||||
|
||||
function load(file) {
|
||||
debug("loading ", file);
|
||||
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
||||
}
|
||||
|
||||
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')) {
|
||||
throw new Error("You must specify configuration as an object or a filename.");
|
||||
}
|
||||
|
||||
if (typeof config === 'string') {
|
||||
debug("config is string");
|
||||
filename = config;
|
||||
config = load(filename);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
var debug = require('./debug')('logger')
|
||||
, levels = require('./levels')
|
||||
, util = require('util');
|
||||
var debug = require('debug')('log4js:logger')
|
||||
, levels = require('./levels');
|
||||
|
||||
module.exports = function Logger(dispatch, category) {
|
||||
if (typeof dispatch !== 'function') {
|
||||
@@ -16,7 +15,7 @@ module.exports = function Logger(dispatch, category) {
|
||||
var args = Array.prototype.slice.call(arguments)
|
||||
, logLevel = args.shift()
|
||||
, loggingEvent = new LoggingEvent(category, logLevel, args);
|
||||
debug("Logging event " + loggingEvent + " to dispatch = " + util.inspect(dispatch));
|
||||
debug("Logging event ", loggingEvent, " to dispatch = ", dispatch);
|
||||
dispatch(loggingEvent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
var fs = require('fs')
|
||||
, stream
|
||||
, debug = require('../debug')('BaseRollingFileStream')
|
||||
, debug = require('debug')('log4js:BaseRollingFileStream')
|
||||
, util = require('util')
|
||||
, semver = require('semver');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||
, debug = require('../debug')('DateRollingFileStream')
|
||||
, debug = require('debug')('log4js:DateRollingFileStream')
|
||||
, format = require('../date_format')
|
||||
, async = require('async')
|
||||
, fs = require('fs')
|
||||
@@ -9,7 +9,7 @@ var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||
module.exports = DateRollingFileStream;
|
||||
|
||||
function DateRollingFileStream(filename, pattern, options, now) {
|
||||
debug("Now is " + now);
|
||||
debug("Now is ", now);
|
||||
if (pattern && typeof(pattern) === 'object') {
|
||||
now = options;
|
||||
options = pattern;
|
||||
@@ -31,7 +31,7 @@ function DateRollingFileStream(filename, pattern, options, now) {
|
||||
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);
|
||||
}
|
||||
@@ -41,8 +41,8 @@ DateRollingFileStream.prototype.shouldRoll = function() {
|
||||
var lastTime = this.lastTimeWeWroteSomething,
|
||||
thisTime = format.asString(this.pattern, new Date(this.now()));
|
||||
|
||||
debug("DateRollingFileStream.shouldRoll with now = " +
|
||||
this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
|
||||
debug("DateRollingFileStream.shouldRoll with now = ",
|
||||
this.now(), ", thisTime = ", thisTime, ", lastTime = ", lastTime);
|
||||
|
||||
this.lastTimeWeWroteSomething = thisTime;
|
||||
this.previousTime = lastTime;
|
||||
@@ -81,7 +81,7 @@ DateRollingFileStream.prototype.roll = function(filename, callback) {
|
||||
}
|
||||
|
||||
function renameTheCurrentFile(cb) {
|
||||
debug("Renaming the " + filename + " -> " + newFilename);
|
||||
debug("Renaming the ", filename, " -> ", newFilename);
|
||||
fs.rename(filename, newFilename, cb);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||
, debug = require('../debug')('RollingFileStream')
|
||||
, debug = require('debug')('log4js:RollingFileStream')
|
||||
, util = require('util')
|
||||
, path = require('path')
|
||||
, fs = require('fs')
|
||||
@@ -53,13 +53,13 @@ RollingFileStream.prototype.roll = function(filename, callback) {
|
||||
|
||||
function increaseFileIndex (fileToRename, cb) {
|
||||
var idx = index(fileToRename);
|
||||
debug('Index of ' + fileToRename + ' is ' + idx);
|
||||
debug('Index of ', fileToRename, ' is ', idx);
|
||||
if (idx < that.backups) {
|
||||
//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
|
||||
fs.unlink(filename + '.' + (idx+1), function (err) {
|
||||
//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);
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user