Constructor
new module:ct-core /log /Log()
Methods
(static) get Logger(class Nameopt)
Gets a logger for a specified classname.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
className |
String |
<optional> |
'caplin' | 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) interpolate(args) → {Array}
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!'; 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, Log.interpolate(arguments)); }
Parameters:
Name | Type | Description |
---|---|---|
args |
Array | 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.
- Type
- Array
(static) log Global Errors()
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) register(logger, class Patternopt)
Registers a logger with the GlobalEventHub.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
logger |
module:ct-core |
the logger that should receive notification of log messages. |
|
classPattern |
String |
<optional> |
allows log messages to be filtered based on the source of the message. e.g. a classPattern of 'caplin.trading.*' will only receive messages logged within the trading library. |
(static) unregister(logger, class Patternopt)
Unregisters a logger from the GlobalEventHub.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
logger |
module:ct-core |
the logger that should stop receiving notification of log messages. |
||
classPattern |
String |
<optional> |
'*' | the class pattern that was used to register the logger. If this argument is not provided, the logger will be unsubscrubed from all packages. |