Generate code! It's what the cool kids are doing!

This commit is contained in:
Andrew Stewart 2014-10-24 14:54:56 -07:00
parent f5de644af7
commit d65742bb49
1 changed files with 8 additions and 29 deletions

View File

@ -12,6 +12,8 @@ var getArgs = function(args) {
return args.length >= 1 ? [].slice.call(args, 0) : [];
};
var levels = ["debug", "info", "warn", "error", "fatal"];
var BasicLogger = require('./logger/basic_logger'),
NullLogger = require('./logger/null_logger');
@ -29,11 +31,7 @@ var Logger = module.exports = {};
Logger.setup = function setup(logger) {
if (logger == null) { logger = BasicLogger; }
if (logger === false) {
this.logger = NullLogger;
} else {
this.logger = logger;
}
this.logger = logger || NullLogger;
return this.logger;
};
@ -42,27 +40,8 @@ Logger.toString = function() {
return this.logger.toString();
};
Logger.debug = function() {
var args = getArgs(arguments);
return this.logger.debug.apply(this.logger, args);
};
Logger.info = function() {
var args = getArgs(arguments);
return this.logger.info.apply(this.logger, args);
};
Logger.warn = function() {
var args = getArgs(arguments);
return this.logger.warn.apply(this.logger, args);
};
Logger.error = function() {
var args = getArgs(arguments);
return this.logger.error.apply(this.logger, args);
};
Logger.fatal = function() {
var args = getArgs(arguments);
return this.logger.fatal.apply(this.logger, args);
};
levels.forEach(function(level) {
Logger[level] = function() {
return this.logger[level].apply(this.logger, arguments);
}
});