wilton.js  v202103141
 All Namespaces Functions
Functions
Logger Namespace Reference

wilton/Logger
Log messages to console or log file. More...

Functions

Undefined debug (String|Object|Error message, Function|Undefined callback)
 Log specified message using DEBUG logging level.
Undefined error (String|Object|Error message, Function|Undefined callback)
 Log specified message using ERROR logging level.
Undefined info (String|Object|Error message, Function|Undefined callback)
 Log specified message using INFO logging level.
static Undefined initConsole (String threshold, Function|Undefined callback)
 Shotcut function for console-only logging initialization.
static Undefined initialize (Object options, Function|Undefined callback)
 Initialize process-wide logging.
Undefined log (String|Object|Error message, Function|Undefined callback)
 Log specified message using DEBUG logging level.
Object Logger (String|Undefined name, Function|Undefined callback)
 Create Logger instance.
static Undefined shutdown (Function|Undefined callback)
 Deinitialize logging subsystem.
Undefined warn (String|Object|Error message, Function|Undefined callback)
 Log specified message using WARN logging level.

Detailed Description

This module allows to log arbitrary messages. It is implemented on top of log4cplus logging library.

Message filtering is based on a specified log level and on a logger name. Loggers are ususally named using "dot notation": myapp.somemodule, myapp.somemodule.submodule etc. Allowed logging level configured for "parent" logger (named myapp in this case will apply to these examples unless special logging level will be configured for them.

For most applications (excluding small scripts) it is expected that logging is configured using Logger.initialize() during the application startup.

Logger instances are effectively "stateless" (only state is a logger name) - they don't hold additional native resources through handles.

Usage example:

// init logging once at app startup
Logger.initialize({
appenders: [
{
appenderType: "DAILY_ROLLING_FILE",
thresholdLevel: "DEBUG",
filePath: "path/to/log/myapp_log.txt"
},
{
appenderType: "CONSOLE",
thresholdLevel: "WARN"
}
],
loggers: {
"wilton": "WARN",
"myapp": "INFO",
"myapp.somemodule.submodule": "DEBUG"
}
});
// create logger instance
var logger = new Logger("myapp.somemodule.submodule");
// log messages
logger.debug("foo");
logger.info("bar");
logger.warn("baz");

Function Documentation

Undefined Logger::debug ( String|Object|Error  message,
Function|Undefined  callback 
)

Logs specified message using DEBUG logging level.

String messages are logged as-is, Objects are converted to JSON, stacktrace are extracted from specified Errors.

Parameters
messageString|Object|Error message to log
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
Undefined Logger::error ( String|Object|Error  message,
Function|Undefined  callback 
)

Logs specified message using ERROR logging level.

String messages are logged as-is, Objects are converted to JSON, stacktrace are extracted from specified Errors.

Parameters
messageString|Object|Error message to log
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
Undefined Logger::info ( String|Object|Error  message,
Function|Undefined  callback 
)

Logs specified message using INFO logging level.

String messages are logged as-is, Objects are converted to JSON, stacktrace are extracted from specified Errors.

Parameters
messageString|Object|Error message to log
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
static Undefined Logger::initConsole ( String  threshold,
Function|Undefined  callback 
)
static

Initializes logging subsystem using only CONSOLE appender and without using specific settings for separate logger.

Parameters
thresholdString threshold logging level for CONSOLE appender, must be one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
static Undefined Logger::initialize ( Object  options,
Function|Undefined  callback 
)
static

Initializes logging subsystem

Should be called as early as possible on application startup.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
Undefined

Options

  • appenders Array list of appenders (log destinations) to configure
    • appenderType String type of the appender, supported values: NULL, CONSOLE, FILE, DAILY_ROLLING_FILE
    • filePath String|Undefined path to the log file, relative path is resolved against current application directory path (that is one level above the executable directory path).
    • layout String|Undefined formatting layout for log messages, see log4cplus docs for details, default value: d{Y-m-d H:M:S,q} [%-5p %-5.5t %-20.20c] mn
    • thresholdLevel String|Undefined minimal logging level for this appender, supported values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
    • useLockFile Boolean|Undefined whether to use lock file for DAILY_ROLLING_FILE appender, default value: false
    • maxBackupIndex Integer|Undefined max number of old (rolled over) log files for DAILY_ROLLING_FILE appender, default value: 16
  • loggers Array|Object list of loggers to configure minimal allowed logging levels
    • name String logger name (Object key can be used instead)
    • level String minimal allowed logging level for this logger (Object value can be used instead), supported values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Undefined Logger::log ( String|Object|Error  message,
Function|Undefined  callback 
)

Logs specified message using DEBUG logging level.

String messages are logged as-is, Objects are converted to JSON, stacktrace are extracted from specified Errors.

Parameters
messageString|Object|Error message to log
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
Object Logger::Logger ( String|Undefined  name,
Function|Undefined  callback 
)

Creates Logger object instace with the specified name, that will be used to select the filtering level for all messages logged through this instance.

Created instance doesn't hold any additional native resources and doesn't need to be closed/destroyed explicitely.

Parameters
nameString|Undefined logger name, default value: wilton
callbackFunction|Undefined callback to receive result or error
Returns
Object Logger instance
static Undefined Logger::shutdown ( Function|Undefined  callback)
static

Deinitialization is an optional operation, logging subsystem will be deinitilized automatically during the shutdown.

Parameters
callbackFunction|Undefined callback to receive result or error
Returns
Undefined
Undefined Logger::warn ( String|Object|Error  message,
Function|Undefined  callback 
)

Logs specified message using WARN logging level.

String messages are logged as-is, Objects are converted to JSON, stacktrace are extracted from specified Errors.

Parameters
messageString|Object|Error message to log
callbackFunction|Undefined callback to receive result or error
Returns
Undefined