Namespace RapidContext.Log

Provides a logging service for debugging apps and server calls.

All log messages are filtered by log level and either discarded or stored to an internal array. Log messages on the error or warning levels are also sent to the server for remote logging.

This module replaces the built-in console.error(), console.warn(), console.info(), console.log() and console.debug() functions with its own versions, passing through the log messages if not filtered.

Source code: RapidContext_Log.js

Namespace Summary
 
Method Summary
<static>  
RapidContext.Log.clear()
Clears the log console and the array of stored messages.
<static>  
RapidContext.Log.context(value)
Returns and optionally sets the current log context.
<static>  
RapidContext.Log.debug(msg)
Logs a debug message with optional data.
<static>  
RapidContext.Log.error(msg)
Logs an error message with optional data.
<static>  
RapidContext.Log.history()
Returns the history of filtered log entries.
<static>  
RapidContext.Log.info(msg)
Logs an information message with optional data.
<static>  
RapidContext.Log.init(opts)
Initializes and configures the logging module.
<static>  
RapidContext.Log.level(value)
Returns and optionally sets the current log level.
<static>  
RapidContext.Log.stringify(val)
Creates a string representation (suitable for logging) for any value or object.
<static>  
RapidContext.Log.warn(msg)
Logs a warning message with optional data.
Namespace Detail
RapidContext.Log
Method Detail
<static> RapidContext.Log.init(opts)
Initializes and configures the logging module. Will modify the console object for logging. This replaces the default console.error, console.warn, console.info, console.log and console.debug functions. Safe to call multiple times to change or update config.
Parameters:
{Object} opts Optional
the log configuration options, or null
{Number} opts.interval Optional
the publish delay in millis, default is 10s
{String} opts.url Optional
the publish URL endpoint
{Function} opts.filter Optional
the event filter, returns a boolean
{Function} opts.publisher Optional
the event publisher, returns a Promise

<static> RapidContext.Log.clear()
Clears the log console and the array of stored messages.

<static> {Array} RapidContext.Log.history()
Returns the history of filtered log entries. Each log entry is a plain object with properties -- id, time, level, context, message and data.
Returns:
{Array} the array of log entries

<static> {String} RapidContext.Log.level(value)
Returns and optionally sets the current log level. The supported log level values are -- none, error, warn, info, log and all.
Parameters:
{String} value Optional
the new log level
Returns:
{String} the current log level

<static> {String} RapidContext.Log.context(value)
Returns and optionally sets the current log context. The log context is used to tag all subsequent log messages until the context is removed or modified.
RapidContext.Log.context('mybutton.onclick');
...
console.warn('unsupported xyz value:', value);
...
RapidContext.Log.context(null);
Parameters:
{String} value Optional
the new log context, or null to clear
Returns:
{String} the current log context, or null for none

<static> RapidContext.Log.error(msg)
Logs an error message with optional data. Also available as the global console.error() function.
console.error('failed to initialize module');
Parameters:
{String} msg
the log message
{Object} ... Optional
the additional log data or messages

<static> RapidContext.Log.warn(msg)
Logs a warning message with optional data. Also available as the global console.warn() function.
console.warn('missing "data" attribute on document root:', document.body);
Parameters:
{String} msg
the log message
{Object} ... Optional
the additional log data or messages

<static> RapidContext.Log.info(msg)
Logs an information message with optional data. Also available as the global console.info() function.
console.info('authorization failed, user not logged in');
Parameters:
{String} msg
the log message
{Object} ... Optional
the additional log data or messages

<static> RapidContext.Log.debug(msg)
Logs a debug message with optional data. Also available as the global console.log() and console.debug() functions.
console.log('init AJAX call to URL:', url);
...
console.log('done AJAX call to URL:', url, responseCode);
Parameters:
{String} msg
the log message
{Object} ... Optional
the additional log data or messages

<static> {String} RapidContext.Log.stringify(val)
Creates a string representation (suitable for logging) for any value or object. The returned string is similar to a JSON representation of the value, but may be simplified for increased readability.
Parameters:
{Object} val
the value or object to convert
Returns:
{String} the string representation of the value