working, except for tests which expect log levels to persist across getLogger calls

This commit is contained in:
Gareth Jones
2013-08-02 15:12:04 +10:00
parent 3b55aefe6f
commit 5bd7ce3ab9
4 changed files with 24 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
"use strict";
var levels = require('./levels')
var debug = require('./debug')('logger')
, levels = require('./levels')
, util = require('util')
, log4js = require('./log4js')
, DEFAULT_CATEGORY = '[default]';
/**
@@ -26,17 +26,20 @@ function LoggingEvent (categoryName, level, data) {
* @param name name of category to log to
* @author Stephan Strittmatter
*/
function Logger (name, level) {
function Logger (name, level, dispatch) {
this.category = name || DEFAULT_CATEGORY;
if (level) {
this.setLevel(level);
}
this.dispatch = dispatch;
}
Logger.DEFAULT_CATEGORY = DEFAULT_CATEGORY;
Logger.prototype.level = levels.TRACE;
Logger.prototype.setLevel = function(level) {
debug("setting level to " + level);
this.level = levels.toLevel(level, this.level || levels.TRACE);
};
@@ -48,8 +51,8 @@ Logger.prototype.log = function() {
var args = Array.prototype.slice.call(arguments)
, logLevel = args.shift()
, loggingEvent = new LoggingEvent(this.category, logLevel, args);
log4js.dispatch(loggingEvent);
debug("Logging event " + loggingEvent + " to dispatch = " + util.inspect(this.dispatch));
this.dispatch(loggingEvent);
};
Logger.prototype.isLevelEnabled = function(otherLevel) {