From 2c7b56853b52107ea29180c63d18a03181e52f56 Mon Sep 17 00:00:00 2001 From: Mike Bardzinski Date: Wed, 2 May 2012 15:41:32 +0100 Subject: [PATCH] Changed toLevel to accept a Log4js.Level (or in fact any object), and try to convert it to a Log4js.Level. Fixes the setLevel asymmetry, where you cannot setLevel(log4js.level.foo) --- lib/levels.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/levels.js b/lib/levels.js index 2429c19..98a5e9b 100644 --- a/lib/levels.js +++ b/lib/levels.js @@ -5,24 +5,29 @@ function Level(level, levelStr) { /** * converts given String to corresponding Level - * @param {String} sArg String value of Level + * @param {String} sArg String value of Level OR Log4js.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 (sArg === null) { + return defaultLevel; + } - if (typeof sArg == "string") { - var s = sArg.toUpperCase(); - if (module.exports[s]) { + if (typeof sArg == "string") { + var s = sArg.toUpperCase(); + if (module.exports[s]) { return module.exports[s]; - } - } - return defaultLevel; + } + else { + return defaultLevel; + } + } + + return toLevel(sArg.toString()); + }; Level.prototype.toString = function() {