From 94dbd22c712871f3b061e1a0c545f43286fcd639 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 4 Jun 2013 08:37:36 +1000 Subject: [PATCH] reduced complex function to smaller ones --- lib/log4js.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/log4js.js b/lib/log4js.js index 3bda547..d632524 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -111,23 +111,31 @@ function addAppender () { } args.forEach(function(category) { - if (!appenders[category]) { - appenders[category] = []; - } - appenders[category].push(appender); + addAppenderToCategory(appender, category); if (category === ALL_CATEGORIES) { - for (var logger in loggers) { - if (loggers.hasOwnProperty(logger)) { - loggers[logger].addListener("log", appender); - } - } + addAppenderToAllLoggers(appender); } else if (loggers[category]) { loggers[category].addListener("log", appender); } }); } +function addAppenderToAllLoggers(appender) { + for (var logger in loggers) { + if (loggers.hasOwnProperty(logger)) { + loggers[logger].addListener("log", appender); + } + } +} + +function addAppenderToCategory(appender, category) { + if (!appenders[category]) { + appenders[category] = []; + } + appenders[category].push(appender); +} + function clearAppenders () { appenders = {}; for (var logger in loggers) {