From fbf930f4f509d0dc7e32f3b1ed2562ce306755c0 Mon Sep 17 00:00:00 2001 From: Steve Krenek Date: Thu, 8 May 2014 11:39:09 -0500 Subject: [PATCH 1/2] trailing whitespace trimmed. --- lib/logger.js | 88 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 4c8b672..46c8298 100755 --- a/lib/logger.js +++ b/lib/logger.js @@ -13,7 +13,7 @@ var _ = require('underscore'), var dom = new Dom.DomResource(); // ============================================================================= -// internal Level class definition +// internal Level class definition function Level(options) { this.level = options.level || 0; this.levelName = options.name || ""; @@ -27,7 +27,7 @@ Level.prototype = { return this.level >= otherLevel.level; }, - isLessThanOrEqualTo: function(otherLevel) { + isLessThanOrEqualTo: function(otherLevel) { return this.level <= otherLevel.level; }, @@ -94,9 +94,9 @@ var getLogger = function(category) { if (! category) { category = DEFAULT_CATEGORY; } - + if (! loggers[category]) { - + loggers[category] = new _Logger({ category:category, level: categoryThresholds[category] @@ -136,7 +136,7 @@ var consoleAppender = function(options) { }; var fileAppender = function(options) { - var layout = options.layout ? layouts[options.layout] : basicLayout; + var layout = options.layout ? layouts[options.layout] : basicLayout; var levelThreshold = levels.ALL; if (options.levelThreshold) { levelThreshold = Level.toLevel(options.levelThreshold); @@ -172,13 +172,13 @@ var urlAppender = function(options) { var verb = options.verb || "POST"; var headers = { "Content-Type": options.contentType || "application/json", - "Content-Length": 0 + "Content-Length": 0 }; var levelThreshold = levels.ALL; if (options.levelThreshold) { levelThreshold = Level.toLevel(options.levelThreshold); } - + return function(loggingEvent) { if (loggingEvent.level.isGreaterThanOrEqualTo(levelThreshold)) { var data = JSON.stringify({ @@ -250,10 +250,10 @@ function fileExists(filename) { // Predefined layouts var basicLayout = function(loggingEvent) { - + var tlc = '['+loggingEvent.startTime.toString('yyyy-MM-dd HH:mm:ss') + '] [' + loggingEvent.level.toString() + '] [' + loggingEvent.category + '] - '; var output = tlc + loggingEvent.message; - + if (loggingEvent.exception) { output += '\n' + tlc; output += loggingEvent.exception.name + ': ' + loggingEvent.exception.message; @@ -290,11 +290,11 @@ var colorize = function(str, style) { }; var coloredLayout = function(loggingEvent) { - var tlc = colorize('['+loggingEvent.startTime.toString('yyyy-MM-dd HH:mm:ss') + '] ', 'grey') - + colorize('[' + loggingEvent.level.toString() + '] ', loggingEvent.level.color) + var tlc = colorize('['+loggingEvent.startTime.toString('yyyy-MM-dd HH:mm:ss') + '] ', 'grey') + + colorize('[' + loggingEvent.level.toString() + '] ', loggingEvent.level.color) + colorize('[' + loggingEvent.category + '] - ', 'grey'); var output = tlc + loggingEvent.message; - + if (loggingEvent.exception) { output += '\n' + tlc; output += loggingEvent.exception.name + ': ' + loggingEvent.exception.message; @@ -354,7 +354,7 @@ var DEFAULT_CATEGORY = 'default', 'passThrough': passThroughLayout }, categoryThresholds = {}; - + // Add some convenience methods to the Logger class. ['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function(levelString) { var level = Level.toLevel(levelString); @@ -371,7 +371,7 @@ function logMessage(fsm, level, args) { if (fsm.loggingEnabled) { if (args) { var _logger = getLogger(args.category); - + // Grok the message to log. var message = null; if (typeof(args) === 'string') { @@ -445,7 +445,7 @@ Logger.prototype = { } } }, - + /** * Looks in the app's options to see if logging was configured, and if so, uses that. If not found, looks elsewhere in the app (files, db, etc.) * @returns {Object} @@ -454,12 +454,12 @@ Logger.prototype = { if (this.options) { return this.options; } else { - // TODO: Check for file, Couchdb, etc. in persistidigitation. + // TODO: Check for file, Couchdb, etc. in persistidigitation. // This block would be equivalent to log4js's findConfiguration method. return undefined; } }, - + /** * Configures the given list of appenders for use within this logger. * @param {Array} appenderList @@ -472,23 +472,23 @@ Logger.prototype = { var curr = appenderList[i]; if (! curr.disabled) { // ignore disabled appenders var appender = null; - + if (curr.type === 'custom') { if (curr.fn) { appender = curr.fn; } } else { appender = appenderTemplates[curr.type](curr.options); - } // end else - - if (appender) { + } // end else + + if (appender) { // Address category inclusion / exclusions if (curr.options.includedCategories) { appender.includedCategories = curr.options.includedCategories; } else if (curr.options.excludedCategories) { appender.excludedCategories = curr.options.excludedCategories; } - + appenders.push(appender); var add = true; for (var category in loggers) { @@ -498,7 +498,7 @@ Logger.prototype = { } else if (appender.excludedCategories && appender.excludedCategories.indexOf(category) > -1) { add = false; } - + if (add) { loggers[category].on('log', appender); } @@ -513,7 +513,7 @@ Logger.prototype = { this.addAppenders([appender]); } }, - + /** * Configures the given list of categories, plues the default. * @param {String} defaultLevel the default logging level for categories @@ -522,12 +522,12 @@ Logger.prototype = { configureCategories: function(defaultLevel, categories) { categoryThresholds[DEFAULT_CATEGORY] = defaultLevel; console.info("Default logging threshold is " + defaultLevel); - + for (var name in categories) { categoryThresholds[name] = categories[name]; } }, - + /** * Configures the given list of templates for use by the logger. * @param {Array} templates @@ -539,7 +539,7 @@ Logger.prototype = { } } }, - + /** * Adds the given template to the logger. * @param {String} id @@ -548,7 +548,7 @@ Logger.prototype = { addTemplate: function(id, template) { return this.templates.add({id:id, template:template}, true); }, - + /** * Removes the given template from the logger. * @param {String} id @@ -556,23 +556,23 @@ Logger.prototype = { removeTemplate: function(id) { return this.removeById(id); }, - + /** * Logs messages in the info level. - * @param {String | Object} options if a String, the message to log. If an object, can contain the following options: + * @param {String | Object} options if a String, the message to log. If an object, can contain the following options: * */ - log: function(options) { + log: function(options) { logMessage(this, 'INFO', options); }, - + /** * Logs messages in the info level. - * @param {String | Object} options if a String, the message to log. If an object, can contain the following options: + * @param {String | Object} options if a String, the message to log. If an object, can contain the following options: *