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.
Examplevar 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
Property | Type | Default Value | Description |
additive | Boolean | set to false to prevent changes to this logger from propogating down. | |
appenders | comb.logging.appenders.Appender | list of appenders this logger currently contains. | |
fullName | String | the full path name of this Logger. | |
isDebug | Boolean | true if this Loggers level is DEBUG | |
isError | Boolean | true if this Loggers level is ERROR | |
isFatal | Boolean | true if this Loggers level is FATAL | |
isInfo | Boolean | true if this Loggers level is INFO | |
isOff | Boolean | true if this Loggers level is OFF | |
isTrace | Boolean | true if this Loggers level is TRACE | |
isWarn | Boolean | true if this Loggers level is WARN | |
level | comb.logging.Level | the level of this Logger | |
name | String | the name of this logger this does not include the dot notated name | |
subLoggers | Array | all loggers this logger is the parent of. | |
Retrieves/Creates a logger based on the name passed in
Argumentsthe name of the logger
function (name){ return rootTree.getLogger(name); }
Return the root of all loggers
Sourcefunction (){ return rootTree.getRootLogger(); }
Add an appender to this logger. If this is additive then the appender is added to all subloggers.
Examplecomb.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
comb.logging.Appender|String
: the appender is an comb.logging.appenders.Appender then it is added. If the appender is a string then comb.logging.appenders.Appender.createAppender will be called to create it.
null
] Object
: If the first argument is a string then the opts will be used as constructor arguments for creating the appender.
comb.logging.Logger
for chaining.
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; }
Short cut to add a list of appenders to this Logger
Argumentscomb.logging.Logger
for chaining.
function (appenders){ appenders.forEach(this.addAppender.bind(this)); return this; }
Log an debug level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.DEBUG].concat(argsToArray(arguments))); }
Log an error level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.ERROR].concat(argsToArray(arguments))); }
Log an fatal level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.FATAL].concat(argsToArray(arguments))); }
Gets an appender from this logger
Argumentsthe name of the appender.
comb.logging.Appender|undefined
returns the appender with the specified name or undefined if it is not found.
function (name){ var ret; if (name in this.__appenders) { ret = this.__appenders[name]; } return ret; }
Creates a log event to be passed to appenders
Argumentsthe level of the logging event
the message to be logged
Object
the logging event
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 }; }
Log an info level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.INFO].concat(argsToArray(arguments))); }
Determines if an appender is attached.
Argumentsthe name of the appender.
function (name){ return (name in this.__appenders); }
Log a message
Argumentsthe level the message is
the message to log.
comb.logging.Logger
for chaining.
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; }
Removes all appenders from this logger and sub loggers if this Logger is additive.
Returnscomb.logging.Logger
for chaining.
function (){ Object.keys(this.__appenders).forEach(this.removeAppender.bind(this)); return this; }
Removes and appender from this logger.
Argumentsthe name of the appender
comb.logging.Logger
for chaining.
function (name){ if (name in this.__appenders) { delete this.__appenders[name]; this._tree.removeAppender(name); } return this; }
Removes a list of appenders from this logger.
Argumentsa list of names of appenders to remove
comb.logging.Logger
for chaining.
function (appenders){ appenders.forEach(this.removeAppender, this); return this; }
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
{info: Function, debug: Function, error: Function, warn: Function, trace: Function, fatal: Function, end: Function}
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; }
Log an trace level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.TRACE].concat(argsToArray(arguments))); }
Log an warn level message
Argumentsthe message to log.
comb.logging.Logger
for chaining.
function (message){ return this.log.apply(this, [Level.WARN].concat(argsToArray(arguments))); }
MIT https://github.com/C2FO/comb/raw/master/LICENSE
git clone git://github.com/C2FO/comb.git