2011-07-13 16:29:53 +08:00
|
|
|
function Level(level, levelStr) {
|
2011-07-12 11:03:17 +08:00
|
|
|
this.level = level;
|
|
|
|
this.levelStr = levelStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* converts given String to corresponding Level
|
|
|
|
* @param {String} sArg String value of Level
|
|
|
|
* @param {Log4js.Level} defaultLevel default Level, if no String representation
|
|
|
|
* @return Level object
|
|
|
|
* @type Log4js.Level
|
|
|
|
*/
|
|
|
|
function toLevel(sArg, defaultLevel) {
|
|
|
|
|
|
|
|
if (sArg === null) {
|
|
|
|
return defaultLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof sArg == "string") {
|
|
|
|
var s = sArg.toUpperCase();
|
|
|
|
if (module.exports[s]) {
|
|
|
|
return module.exports[s];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaultLevel;
|
|
|
|
};
|
|
|
|
|
|
|
|
Level.prototype.toString = function() {
|
|
|
|
return this.levelStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
Level.prototype.isLessThanOrEqualTo = function(otherLevel) {
|
|
|
|
if (typeof otherLevel === "string") {
|
|
|
|
otherLevel = Level.toLevel(otherLevel);
|
|
|
|
}
|
|
|
|
return this.level <= otherLevel.level;
|
|
|
|
};
|
|
|
|
|
|
|
|
Level.prototype.isGreaterThanOrEqualTo = function(otherLevel) {
|
|
|
|
if (typeof otherLevel === "string") {
|
|
|
|
otherLevel = Level.toLevel(otherLevel);
|
|
|
|
}
|
|
|
|
return this.level >= otherLevel.level;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
2011-07-13 16:29:53 +08:00
|
|
|
ALL: new Level(Number.MIN_VALUE, "ALL")
|
|
|
|
, TRACE: new Level(5000, "TRACE")
|
|
|
|
, DEBUG: new Level(10000, "DEBUG")
|
|
|
|
, INFO: new Level(20000, "INFO")
|
|
|
|
, WARN: new Level(30000, "WARN")
|
|
|
|
, ERROR: new Level(40000, "ERROR")
|
|
|
|
, FATAL: new Level(50000, "FATAL")
|
|
|
|
, OFF: new Level(Number.MAX_VALUE, "OFF")
|
2011-07-12 11:03:17 +08:00
|
|
|
, toLevel: toLevel
|
|
|
|
};
|