2013-05-30 06:26:03 +08:00
|
|
|
"use strict";
|
|
|
|
|
2011-07-13 16:29:53 +08:00
|
|
|
function Level(level, levelStr) {
|
2013-05-30 06:26:03 +08:00
|
|
|
this.level = level;
|
|
|
|
this.levelStr = levelStr;
|
2011-07-12 11:03:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* converts given String to corresponding Level
|
2012-05-02 22:41:32 +08:00
|
|
|
* @param {String} sArg String value of Level OR Log4js.Level
|
2011-07-12 11:03:17 +08:00
|
|
|
* @param {Log4js.Level} defaultLevel default Level, if no String representation
|
|
|
|
* @return Level object
|
|
|
|
* @type Log4js.Level
|
|
|
|
*/
|
|
|
|
function toLevel(sArg, defaultLevel) {
|
|
|
|
|
2012-05-09 14:40:27 +08:00
|
|
|
if (!sArg) {
|
2013-05-30 06:26:03 +08:00
|
|
|
return defaultLevel;
|
2012-05-02 22:41:32 +08:00
|
|
|
}
|
2011-07-12 11:03:17 +08:00
|
|
|
|
2012-05-02 22:41:32 +08:00
|
|
|
if (typeof sArg == "string") {
|
2013-05-30 06:26:03 +08:00
|
|
|
var s = sArg.toUpperCase();
|
|
|
|
if (module.exports[s]) {
|
|
|
|
return module.exports[s];
|
|
|
|
} else {
|
|
|
|
return defaultLevel;
|
|
|
|
}
|
2012-05-02 22:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return toLevel(sArg.toString());
|
2013-05-30 06:26:03 +08:00
|
|
|
}
|
2011-07-12 11:03:17 +08:00
|
|
|
|
|
|
|
Level.prototype.toString = function() {
|
2013-05-30 06:26:03 +08:00
|
|
|
return this.levelStr;
|
2011-07-12 11:03:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Level.prototype.isLessThanOrEqualTo = function(otherLevel) {
|
2013-05-30 06:26:03 +08:00
|
|
|
if (typeof otherLevel === "string") {
|
|
|
|
otherLevel = toLevel(otherLevel);
|
|
|
|
}
|
|
|
|
return this.level <= otherLevel.level;
|
2011-07-12 11:03:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Level.prototype.isGreaterThanOrEqualTo = function(otherLevel) {
|
2013-05-30 06:26:03 +08:00
|
|
|
if (typeof otherLevel === "string") {
|
|
|
|
otherLevel = toLevel(otherLevel);
|
|
|
|
}
|
|
|
|
return this.level >= otherLevel.level;
|
2011-07-12 11:03:17 +08:00
|
|
|
};
|
|
|
|
|
2012-06-01 09:11:07 +08:00
|
|
|
Level.prototype.isEqualTo = function(otherLevel) {
|
2013-05-30 06:26:03 +08:00
|
|
|
if (typeof otherLevel == "string") {
|
|
|
|
otherLevel = toLevel(otherLevel);
|
|
|
|
}
|
|
|
|
return this.level === otherLevel.level;
|
|
|
|
};
|
2012-06-01 09:11:07 +08:00
|
|
|
|
2011-07-12 11:03:17 +08:00
|
|
|
module.exports = {
|
2013-05-30 06:26:03 +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"),
|
|
|
|
toLevel: toLevel
|
2011-07-12 11:03:17 +08:00
|
|
|
};
|