RingoJS

Module ringo/logging

This module provides generic logging support for Ringo applications. It uses SLF4J or Apache log4j if either is detected in the classpath, and will fall back to java.util.logging otherwise.

If the first argument passed to any of the logging methods is a string containing any number of curly bracket pairs ({}), the logger will interpret it as format string and use any following arguments to replace the curly bracket pairs. If an argument is an Error or Java Exception object, the logger will render a stack trace for it and append it to the log message.

This module's exports object implements the EventEmitter interface and emits logged messages using the log level name as event type.

Example

// Get a Logger for the current module
const log = require('ringo/logging').getLogger(module.id);

log.debug('Connected to ', url, ' [GET]');
log.error('This should not occur');
log.info('Info message');
log.info('User {} accessed {}', username, resource);
log.warn('A warning');

Functions


Logger (name, impl)

Logger class. This constructor is not exported, use this module's {@link getLogger} to get a logger instance.

Parameters

String name

the Logger name

Object impl

the logger implementation

See


Logger.prototype. debug ()


Logger.prototype. error ()


Logger.prototype. info ()


Logger.prototype. isDebugEnabled ()


Logger.prototype. isErrorEnabled ()


Logger.prototype. isInfoEnabled ()


Logger.prototype. isTraceEnabled ()


Logger.prototype. isWarnEnabled ()


Logger.prototype. trace ()


Logger.prototype. warn ()


getJavaStack (error, prefix)

Get a rendered JavaScript stack trace from a caught error.

Parameters

Error error

an error object

String prefix

to prepend to result if available

Returns

String

the rendered JavaScript stack trace


getLogger (name)

Get a logger for the given name.

Parameters

String name

the name of the logger. To ensure dot-separated logger names, module hierarchy separators (/) will be replaced with a dot.

Returns

Logger

a logger instance for the given name


getScriptStack (error, prefix)

Get a rendered JavaScript stack trace from a caught error.

Parameters

Error error

an error object

String prefix

to prepend to result if available

Returns

String

the rendered JavaScript stack trace


setConfig (resource, watchForUpdates)

Configure log4j2 using the given file resource.

Parameters

FileResource|string resource

the configuration resource in a valid format; or a string with the path to the configuration file.

Boolean watchForUpdates

if true a scheduler thread is started that repeatedly checks the resource for updates.