From 22c156582f56ca0f762ad8f7fce78d2e02324177 Mon Sep 17 00:00:00 2001 From: jci-fox Date: Tue, 4 Mar 2014 09:08:27 -0600 Subject: [PATCH 1/2] Adding level checks on dynamic logging using levels.toLevel and this.isLevelEnabled prior to emiting the event will prevent the appenders from being notified if the log level provided is below the loggers level. --- lib/logger.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 4da0daf..1c6ff50 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -49,9 +49,12 @@ Logger.prototype.removeLevel = function() { Logger.prototype.log = function() { var args = Array.prototype.slice.call(arguments) - , logLevel = args.shift() - , loggingEvent = new LoggingEvent(this.category, logLevel, args, this); - this.emit("log", loggingEvent); + , logLevel = levels.toLevel(args.shift()) + , loggingEvent; + if (this.isLevelEnabled(logLevel)) { + loggingEvent = new LoggingEvent(this.category, logLevel, args, this); + this.emit("log", loggingEvent); + } }; Logger.prototype.isLevelEnabled = function(otherLevel) { From 73344ba79feb7b1190ee361a298b7d9ec410190f Mon Sep 17 00:00:00 2001 From: jci-fox Date: Tue, 4 Mar 2014 09:27:04 -0600 Subject: [PATCH 2/2] fixing unit test logger.log requires 2 params, and with the 1st being level and filtering the level, the log call must provide a level that will result in log messages --- test/logglyAppender-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/logglyAppender-test.js b/test/logglyAppender-test.js index 7be81e3..30937dc 100644 --- a/test/logglyAppender-test.js +++ b/test/logglyAppender-test.js @@ -70,7 +70,7 @@ vows.describe('log4js logglyAppender').addBatch({ tags: ['loggly-tag1', 'loggly-tag2', 'loggly-tagn'] }); - setup.logger.log('Log event #1'); + setup.logger.log('trace', 'Log event #1'); return setup; }, 'there should be one message only': function (topic) {