new CLogger(id, opts)
CLogger - A node.js logger.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | (optional) - An internal identifier. |
opts |
object | (optional) - An object, holding options to configure the logger instance. At the moment, the only configurable options, are an array of transports to be used and an array of visible log-levels. Log-levels can be given as environment-variables in the form of 'VISIBLE=info,warn,error node app.js'. |
- Source:
Example
var CLogger = require('node-clogger');
var logger = new CLogger('server', {
transports: [
new CLogger.transports.Console()
],
visible: ['info', 'error']
});
logger.info('Outputs something to the node console...');
Methods
-
(static) addTransport(transport) → {object}
-
Add an instance of Transport to the list of used transports. This can be useful, if one will combine the default console transport with logging to a log-file.
Parameters:
Name Type Description transport
object An instance of Transport. - Source:
Returns:
this- Type
- object
-
(static) extend(obj) → {function}
-
A method to extend an ordinary object with logging capabilities. It creates a method for each log-level and stores the logger itself in 'obj._logger'.
Parameters:
Name Type Description obj
object An object to extend with logging functions. - Source:
Returns:
- A function to undo logging extensions.- Type
- function
Example
var clogger = require('node-clogger'); new CLogger().addTransport(new CLogger.transports.LogFile({ 'filename': __dirname + '/server.log' })).extend(console); console.info('This message will be printed on console and in a logfile...');
-
(static) log(level, message, args) → {object}
-
This function is called internally by the different log-functions like CLogger.info. It can be used to log to custom log-levels.
Parameters:
Name Type Description level
string A log-level, represented by a string. Valid default log-levels are 'info', 'warn', 'debug', 'error' and 'trace'. message
string A message to log. args
* (optional) - If the message argument contains placeholder like '%s' for a string, the args can be appended to this function and will be replaced by the placeholder. See node's util.format for valid placeholder and format options. - Source:
Returns:
this- Type
- object
-
(static) trace(message, args) → {object}
-
This method delegates the message and its arguments to the CLogger.log method.
Parameters:
Name Type Description message
string A message to log. args
* (optional) - See CLogger.log. - Source:
Returns:
this- Type
- object