This class is the entry point for all logging actions in comb.

Logger should be retrieved by calling Logger.getLogger() NOT through the new keyword

All loggers in comb follow a heirarchy of inheritance based on a dot notation.

                         rootLogger - ""
                                 /         \
                              "my"      "myOther"
                              /               \
                        "my.logger"       "myOther.logger"
                           /                     \
                      "my.logger.Log"        "myOther.logger.Log"

    
In the above Tree the rootLogger is the base for all logger. my and myOther inherit from rootLogger my.logger inherits from my, and myOther.logger inherits from myOther. The logs do not have to be retrieved in order. If I set rootLogger to ERROR level and added a console appender to it the appender and level will be added to all logs. However if I set my to INFO level and add a fileAppender to it the level and appender will only be added to logs in "my" subtree. If you set my.logger to not be additive then levels, and appenders will not propogate down to the rest of the tree.

For information on levels see comb.logging.Level.

For information on appenders see

For information on configurators see comb.logging.BasicConfigurator or comb.logging.PropertyConfigurator.

Example
var logger = comb.logger;

//configure you logging environement
logger.configure();

//add a file appender to all loggers
logger.configure(logger.appender("FileAppender", {file : "/var/log/myLog.log"});

//Retreiving a logger.
var combLogger = logger("comb");
var combCollectionLogger = logger("comb.collections");
var treeLogger = logger("comb.collections.Tree")
                     //add a JSON appender to tree logger just for fun!
                     .addAppender("JSONAppender", {file : "/var/log/myTreeLogger.json"})

//set my treeLogger to DEBUG Level
treeLogger.level = "DEBUG";
            
Instance Properties
PropertyTypeDefault ValueDescription
additiveBoolean

set to false to prevent changes to this logger from propogating down.

appenderscomb.logging.appenders.Appender

list of appenders this logger currently contains.

fullNameString

the full path name of this Logger.

isDebugBoolean

true if this Loggers level is DEBUG

isErrorBoolean

true if this Loggers level is ERROR

isFatalBoolean

true if this Loggers level is FATAL

isInfoBoolean

true if this Loggers level is INFO

isOffBoolean

true if this Loggers level is OFF

isTraceBoolean

true if this Loggers level is TRACE

isWarnBoolean

true if this Loggers level is WARN

levelcomb.logging.Level

the level of this Logger

nameString

the name of this logger this does not include the dot notated name

subLoggersArray

all loggers this logger is the parent of.

Constructor

Defined logging/index.js

getLogger Static Function Public


Defined logging/index.js

Retrieves/Creates a logger based on the name passed in

Arguments Source
function (name){
   return rootTree.getLogger(name);
           
}
    

getRootLogger Static Function Public


Defined logging/index.js

Return the root of all loggers

Source
function (){
   return rootTree.getRootLogger();
           
}
    

addAppender Function Public


Defined logging/index.js

Add an appender to this logger. If this is additive then the appender is added to all subloggers.

Example
comb.logger("my.logger")
 .addAppender("ConsoleAppender")
 .addAppender("FileAppender", {file:'/var/log/my.log'})
 .addAppender("RollingFileAppender", {file:'/var/log/myRolling.log'})
 .addAppender("JSONAppender", {file:'/var/log/myJson.log'});
        
Arguments Returns Source
function (appender,opts){
   var args = argsToArray(arguments);
   if (isString(appender)) {
       this.addAppender(Appender.createAppender(appender, opts));
   } else {
       if (!isUndefinedOrNull(appender)) {
           var name = appender.name;
           if (!(name in this.__appenders)) {
               this.__appenders[name] = appender;
               if (!appender.level) {
                   appender.level = this.level;
               }
               this._tree.addAppender(appender);
           }
       }
   }
   return this;
           
}
    

addAppenders Function Public


Defined logging/index.js

Short cut to add a list of appenders to this Logger

Arguments Returns Source
function (appenders){
   appenders.forEach(this.addAppender.bind(this));
   return this;
           
}
    

debug Function Public


Defined logging/index.js

Log an debug level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.DEBUG].concat(argsToArray(arguments)));
           
}
    

error Function Public


Defined logging/index.js

Log an error level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.ERROR].concat(argsToArray(arguments)));
           
}
    

fatal Function Public


Defined logging/index.js

Log an fatal level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.FATAL].concat(argsToArray(arguments)));
           
}
    

getAppender Function Public


Defined logging/index.js

Gets an appender from this logger

Arguments Returns Source
function (name){
   var ret;
   if (name in this.__appenders) {
       ret = this.__appenders[name];
   }
   return ret;
           
}
    

getLogEvent Function Public


Defined logging/index.js

Creates a log event to be passed to appenders

Arguments Returns Source
function (level,message,rawMessage){
   return {
       hostname: os.hostname(),
       pid: process.pid,
       gid: hasGetGid ? process.getgid() : null,
       processTitle: process.title,
       level: level,
       levelName: level.name,
       message: message,
       timeStamp: new Date(),
       name: this.fullName,
       rawMessage: rawMessage
   };
           
}
    

info Function Public


Defined logging/index.js

Log an info level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.INFO].concat(argsToArray(arguments)));
           
}
    

isAppenderAttached Function Public


Defined logging/index.js

Determines if an appender is attached.

Arguments Source
function (name){
   return (name in this.__appenders);
           
}
    

log Function Public


Defined logging/index.js

Log a message

Arguments Returns Source
function (level,message){
   var rawMessage = message;
   level = Level.toLevel(level);
   if (this.hasLevelGt(level)) {
       var args = argsToArray(arguments, 1);
       if (args.length > 1) {
           message = format.apply(null, args);
       }
       if (Level.TRACE.equals(level)) {
           var err = new Error;
           err.name = "Trace";
           err.message = message || '';
           Error.captureStackTrace(err, log);
           message = err.stack;
       } else if (Level.ERROR.equals(level) && isInstanceOf(message, Error)) {
           message = message.stack;
       }
       var type = level.name.toLowerCase(), appenders = this.__appenders;
       var event = this.getLogEvent(level, message, rawMessage);
       Object.keys(appenders).forEach(function (i) {
           appenders[i].append(event);
       });
   }
   return this;
           
}
    

removeAllAppenders Function Public


Defined logging/index.js

Removes all appenders from this logger and sub loggers if this Logger is additive.

Returns Source
function (){
   Object.keys(this.__appenders).forEach(this.removeAppender.bind(this));
   return this;
           
}
    

removeAppender Function Public


Defined logging/index.js

Removes and appender from this logger.

Arguments Returns Source
function (name){
   if (name in this.__appenders) {
       delete this.__appenders[name];
       this._tree.removeAppender(name);
   }
   return this;
           
}
    

removeAppenders Function Public


Defined logging/index.js

Removes a list of appenders from this logger.

Arguments Returns Source
function (appenders){
   appenders.forEach(this.removeAppender, this);
   return this;
           
}
    

timer Function Public


Defined logging/index.js

Create a timer that can be used to log statements with a duration at the send.

var timer = LOGGER.timer();
setTimeout(function(){
     timer.info("HELLO TIMERS!!!"); //HELLO TIMERS!!! [Duration: 5000ms]
}, 5000);

Arguments Returns Source
function (timerFormat){
   timerFormat = timerFormat || " [Duration: %dms]";
   function timerLog(level, start) {
       return function (message) {
           var args = argsToArray(arguments, 1);
           message += timerFormat;
           args.push(new Date() - start);
           self.log.apply(self, [level, message].concat(args));
           return ret;
       };
   }
   var start = new Date(),
       self = this,
       ret = {
           info: timerLog(Level.INFO, start),
           debug: timerLog(Level.DEBUG, start),
           error: timerLog(Level.ERROR, start),
           warn: timerLog(Level.WARN, start),
           trace: timerLog(Level.TRACE, start),
           fatal: timerLog(Level.FATAL, start),
           log: function (level) {
               return timerLog(level, start).apply(this, argsToArray(arguments, 1));
           },
           end: function () {
               start = self = null;
           }
       };
   return ret;
           
}
    

trace Function Public


Defined logging/index.js

Log an trace level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.TRACE].concat(argsToArray(arguments)));
           
}
    

warn Function Public


Defined logging/index.js

Log an warn level message

Arguments Returns Source
function (message){
   return this.log.apply(this, [Level.WARN].concat(argsToArray(arguments)));
           
}
    

License

MIT https://github.com/C2FO/comb/raw/master/LICENSE

Meta