got rid of the __preLog4js stuff from the console.log replacement

This commit is contained in:
Gareth Jones 2012-02-22 08:53:28 +11:00
parent cff20b99e3
commit 53367785b4
3 changed files with 26 additions and 21 deletions

View File

@ -357,28 +357,30 @@ function configure (configurationFileOrObject, options) {
configureOnceOff(config);
}
var originalConsoleFunctions = {
log: console.log,
debug: console.debug,
info: console.info,
warn: console.warn,
error: console.error
};
function replaceConsole(logger) {
function replaceWith(fn) {
return function() {
fn.apply(logger, arguments);
}
}
if (console['_preLog4js_log'] === undefined) {
logger = logger || getLogger("console");
['log','debug','info','warn','error'].forEach(function (item) {
console['_preLog4js_'+item] = console[item];
console[item] = replaceWith(item === 'log' ? logger.info : logger[item]);
});
}
logger = logger || getLogger("console");
['log','debug','info','warn','error'].forEach(function (item) {
console[item] = replaceWith(item === 'log' ? logger.info : logger[item]);
});
}
function restoreConsole() {
if (console['_preLog4js_log']) {
['log', 'debug', 'info', 'warn', 'error'].forEach(function (item) {
console[item] = console['_preLog4js_'+item];
delete console['_preLog4js_'+item];
});
}
['log', 'debug', 'info', 'warn', 'error'].forEach(function (item) {
console[item] = originalConsoleFunctions[item];
});
}
function loadAppender(appender) {

View File

@ -5,8 +5,8 @@ events = require('events'),
async = require('async');
function debug(message) {
// util.debug(message);
console.log(message);
util.debug(message);
// console.log(message);
}
function BufferedWriteStream(stream) {

View File

@ -20,6 +20,7 @@ vows.describe('log4js fileAppender').addBatch({
var that = this, testFile = __dirname + '/fa-default-test.log'
, logger = log4js.getLogger('default-settings');
remove(testFile);
log4js.clearAppenders();
log4js.addAppender(log4js.fileAppender(testFile), 'default-settings');
logger.info("This should be in the file.");
@ -43,6 +44,7 @@ vows.describe('log4js fileAppender').addBatch({
remove(testFile);
remove(testFile + '.1');
//log file of 100 bytes maximum, no backups
log4js.clearAppenders();
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 an intermediate log message.");
@ -76,6 +78,7 @@ vows.describe('log4js fileAppender').addBatch({
remove(testFile+'.2');
//log file of 50 bytes maximum, 2 backups
log4js.clearAppenders();
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 second log message.");