enhanced console.log

This commit is contained in:
csausdev
2010-12-08 08:53:59 +11:00
parent 2e3843205a
commit c2f9ccce73
4 changed files with 60 additions and 8 deletions

View File

@@ -45,12 +45,12 @@
* Website: http://log4js.berlios.de
*/
module.exports = function (fileSystem, standardOutput, configPaths) {
var fs = fileSystem || require('fs'),
standardOutput = standardOutput || console.log,
configPaths = configPaths || require.paths,
sys = require('sys'),
events = require('events'),
var events = require('events'),
path = require('path'),
sys = require('sys'),
fs = fileSystem || require('fs'),
standardOutput = standardOutput || sys.puts,
configPaths = configPaths || require.paths,
DEFAULT_CATEGORY = '[default]',
ALL_CATEGORIES = '[all]',
loggers = {},
@@ -614,8 +614,26 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
};
function replaceConsole(logger) {
function replaceWith (fn) {
return function() {
fn.apply(logger, arguments);
}
}
console.log = replaceWith(logger.info);
console.debug = replaceWith(logger.debug);
console.trace = replaceWith(logger.trace);
console.info = replaceWith(logger.info);
console.warn = replaceWith(logger.warn);
console.error = replaceWith(logger.error);
}
//set ourselves up if we can find a default log4js.json
configure(findConfiguration());
//replace console.log, etc with log4js versions
replaceConsole(getLogger("console"));
return {
getLogger: getLogger,