got rid of the __preLog4js stuff from the console.log replacement
This commit is contained in:
parent
cff20b99e3
commit
53367785b4
@ -357,28 +357,30 @@ function configure (configurationFileOrObject, options) {
|
|||||||
configureOnceOff(config);
|
configureOnceOff(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var originalConsoleFunctions = {
|
||||||
|
log: console.log,
|
||||||
|
debug: console.debug,
|
||||||
|
info: console.info,
|
||||||
|
warn: console.warn,
|
||||||
|
error: console.error
|
||||||
|
};
|
||||||
|
|
||||||
function replaceConsole(logger) {
|
function replaceConsole(logger) {
|
||||||
function replaceWith(fn) {
|
function replaceWith(fn) {
|
||||||
return function() {
|
return function() {
|
||||||
fn.apply(logger, arguments);
|
fn.apply(logger, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (console['_preLog4js_log'] === undefined) {
|
logger = logger || getLogger("console");
|
||||||
logger = logger || getLogger("console");
|
['log','debug','info','warn','error'].forEach(function (item) {
|
||||||
['log','debug','info','warn','error'].forEach(function (item) {
|
console[item] = replaceWith(item === 'log' ? logger.info : logger[item]);
|
||||||
console['_preLog4js_'+item] = console[item];
|
});
|
||||||
console[item] = replaceWith(item === 'log' ? logger.info : logger[item]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreConsole() {
|
function restoreConsole() {
|
||||||
if (console['_preLog4js_log']) {
|
['log', 'debug', 'info', 'warn', 'error'].forEach(function (item) {
|
||||||
['log', 'debug', 'info', 'warn', 'error'].forEach(function (item) {
|
console[item] = originalConsoleFunctions[item];
|
||||||
console[item] = console['_preLog4js_'+item];
|
});
|
||||||
delete console['_preLog4js_'+item];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAppender(appender) {
|
function loadAppender(appender) {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
var util = require('util'),
|
var util = require('util'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
events = require('events'),
|
events = require('events'),
|
||||||
async = require('async');
|
async = require('async');
|
||||||
|
|
||||||
function debug(message) {
|
function debug(message) {
|
||||||
// util.debug(message);
|
util.debug(message);
|
||||||
console.log(message);
|
// console.log(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BufferedWriteStream(stream) {
|
function BufferedWriteStream(stream) {
|
||||||
@ -265,4 +265,4 @@ RollingFileStream.prototype.roll = function(filename, callback) {
|
|||||||
|
|
||||||
exports.BaseRollingFileStream = BaseRollingFileStream;
|
exports.BaseRollingFileStream = BaseRollingFileStream;
|
||||||
exports.RollingFileStream = RollingFileStream;
|
exports.RollingFileStream = RollingFileStream;
|
||||||
exports.BufferedWriteStream = BufferedWriteStream;
|
exports.BufferedWriteStream = BufferedWriteStream;
|
||||||
|
@ -20,6 +20,7 @@ vows.describe('log4js fileAppender').addBatch({
|
|||||||
var that = this, testFile = __dirname + '/fa-default-test.log'
|
var that = this, testFile = __dirname + '/fa-default-test.log'
|
||||||
, logger = log4js.getLogger('default-settings');
|
, logger = log4js.getLogger('default-settings');
|
||||||
remove(testFile);
|
remove(testFile);
|
||||||
|
log4js.clearAppenders();
|
||||||
log4js.addAppender(log4js.fileAppender(testFile), 'default-settings');
|
log4js.addAppender(log4js.fileAppender(testFile), 'default-settings');
|
||||||
|
|
||||||
logger.info("This should be in the file.");
|
logger.info("This should be in the file.");
|
||||||
@ -43,6 +44,7 @@ vows.describe('log4js fileAppender').addBatch({
|
|||||||
remove(testFile);
|
remove(testFile);
|
||||||
remove(testFile + '.1');
|
remove(testFile + '.1');
|
||||||
//log file of 100 bytes maximum, no backups
|
//log file of 100 bytes maximum, no backups
|
||||||
|
log4js.clearAppenders();
|
||||||
log4js.addAppender(log4js.fileAppender(testFile, log4js.layouts.basicLayout, 100, 0), 'max-file-size');
|
log4js.addAppender(log4js.fileAppender(testFile, log4js.layouts.basicLayout, 100, 0), 'max-file-size');
|
||||||
logger.info("This is the first log message.");
|
logger.info("This is the first log message.");
|
||||||
logger.info("This is an intermediate log message.");
|
logger.info("This is an intermediate log message.");
|
||||||
@ -76,6 +78,7 @@ vows.describe('log4js fileAppender').addBatch({
|
|||||||
remove(testFile+'.2');
|
remove(testFile+'.2');
|
||||||
|
|
||||||
//log file of 50 bytes maximum, 2 backups
|
//log file of 50 bytes maximum, 2 backups
|
||||||
|
log4js.clearAppenders();
|
||||||
log4js.addAppender(log4js.fileAppender(testFile, log4js.layouts.basicLayout, 50, 2), 'max-file-size-backups');
|
log4js.addAppender(log4js.fileAppender(testFile, log4js.layouts.basicLayout, 50, 2), 'max-file-size-backups');
|
||||||
logger.info("This is the first log message.");
|
logger.info("This is the first log message.");
|
||||||
logger.info("This is the second log message.");
|
logger.info("This is the second log message.");
|
||||||
@ -146,4 +149,4 @@ vows.describe('log4js fileAppender').addBatch({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
Loading…
Reference in New Issue
Block a user