Documentation Menu

log Method

Creates a log item

Definition

log(level: number, logObject: any): Logger

Parameters

level Numeric severity of the message to be logged.
logObject String or object to be logged, or a function that returns the string or object to be logged. See remarks.

Return Value

The Logger itself.

Remarks

You are not restricted to simply logging strings. You can log objects, arrays, dates, numbers, booleans and even regular expressions. These are all converted to a string before being logged.

If producing the log information is expensive, than you will only want to do this if the information will actually be logged - that is, the severity of the logged information exceeds the logger's level, etc.

To solve this, you can pass in a function rather than the information itself. This function has to return the information. It will only be called if the log information will actually be logged.

You can even have the function return another function that returns the actual information - or another function, etc. Do make sure there are no circular references in this chain, otherwise you will get a stack overflow.

Examples

This creates a log message "log message" with severity 2500.

JL().log(2500, "log message");

This logs an object.

var obj = {"f1": "v1", "f2": "v2"};
JL().log(2500, obj);

This passes in a function that produces the log information. The function is only called if the log information will actually be logged.

JL().log(2500, function() { return "log message"; });