Package
caplin.core.log

Log

caplin.core.log.Log contains utility methods for logging.

Constructor Summary

Attributes Name and Description
caplin.core.log.Log()

Method Summary

Attributes Name and Description
<static> void getLogger(String className)

Gets a logger for a specified classname.

<static> Array interpolate(Array args)

Applies a template that is the first item in an array or arguments object.

<static> void logGlobalErrors()

Uses window.onerror to get notified about all errors on the page and add them to the log.

<static> void register(caplin.core.log.Logger logger, String classPattern)

Registers a logger with the GlobalEventHub.

<static> void unregister(caplin.core.log.Logger logger, String classPattern)

Unregisters a logger from the GlobalEventHub.

Constructor Detail

caplin.core.log.Log()

Method Detail

<static> void getLogger(String className)

Gets a logger for a specified classname.

Parameters
String className the source of log messages published using this logger. If this is not provided, it will default to 'caplin', but this is for legacy purposes. You should always use the name of the class within which you will be using this logger.

<static> Array interpolate(Array args)

Applies a template that is the first item in an array or arguments object.

If the first item in the array is a string, it is treated as a template. When a number in curly braces (e.g. {0} ) appears in the string, it is replaced with the equivalent argument. {0} refers to the first item after the template, {1} to the second, etc.

Here's an example of the interpolation mechanism:

var animalType = "a cat";
var animalName = "Mittens";
var animalSound = "meow!";
caplin.core.log.Log.interpolate( [ "{0} is {1}, or something like {1}.", animalName, animalType, animalSound ] );
will return the array:
["Mittens is a cat, or something like a cat.", "meow!"]

An example use of this method:

MyConsoleLogger.prototype.warn = function() {
	 console.warn.apply(console, caplin.core.log.Log.interpolate(arguments));
}

Parameters
Array args An array(like) of things that should be logged. If the first argument is a string it will be considered as a template and interpolation will be performed. May not be null or undefined.
Returns
a copy of the provided array, with the first string replaced with the interpolated version, and any items that were interpolated removed.

<static> void logGlobalErrors()

Uses window.onerror to get notified about all errors on the page and add them to the log. This assumes you are running in a browser and sets 'onerror' on a 'window' global.

<static> void register(caplin.core.log.Logger logger, String classPattern)

Registers a logger with the GlobalEventHub.

Parameters
caplin.core.log.Logger logger the logger that should receive notification of log messages.
String classPattern an optional pattern allowing you to filter log messages based on the source of the message. e.g. a classPattern of 'caplin.trading.*' will only receive messages logged within the trading library.

<static> void unregister(caplin.core.log.Logger logger, String classPattern)

Unregisters a logger from the GlobalEventHub.

Parameters
caplin.core.log.Logger logger the logger that should stop receiving notification of log messages.
String classPattern the class pattern that was used to register the logger.