Documentation Menu

setOptions Method

Sets options for an ajax appender.

Definition

setOptions(options: any): AjaxAppender

Parameters

options A JSON object with options. See the Remarks sections below.

Return Value

The AjaxAppender itself.

Remarks

The JSON object can have the following fields:

Field Type Default Description
level
optional
number TRACE Numeric severity. Only log messages with a severity equal or higher than this can be sent to the server.
userAgentRegex
optional
regular expression (empty) If not empty, log messages only get processed if this regular expression matches the user agent string of the browser.
ipRegex
optional
regular expression (empty) If not empty, log messages only get processed if this regular expression matches the IP address(es) from which the page was loaded. If you use this, be sure to set the IP address via the setOptions method of the JL object.
disallow
optional
regular expression (empty) If not empty, log messages are suppressed if they match this regular expression. If an object is being logged, it is converted to a JSON string, which is then matched.
storeInBufferLevel
optional
number ALL If the severity of the log message is equal or greater than this, but smaller than level, the log message will not be sent to the server, but stored in an internal buffer.

If bufferSize is 0 or less, the log message is simply ignored.

sendWithBufferLevel
optional
number OFF If the severity of a log message is equal or greater than this, not only the log message but also all log messages stored in the internal buffer will be sent to the server.

This allows you to store low priority trace messages in the internal buffer, and only send them when a high priority fatal message is sent.

bufferSize
optional
number 0 Sets the size of the buffer used with sendWithBufferLevel and storeInBufferLevel.
batchSize
optional
number 1 Allows you to improve performance by sending multiple log messages in one go, rather than one by one (details).
batchTimeout
optional
number (no timeout) Usefull when batching log messages. If set, log messages are guaranteed to be sent within this period (in milli seconds), even if the batch size has not been reached yet (details).
maxBatchSize
optional
number 20 When the server is unreachable and log messages are being stored until it is reachable again, this is the maximum number of messages that will be stored. Cannot be smaller than batchSize (details).
sendTimeout
optional
number 5000 If no response has been received for a log request after this many milli seconds, the outstanding request is aborted and a new request sent with the log messages (details).
url
optional
string defaultAjaxUrl See Setting the url to send logs to.
beforeSend
optional
function (empty) Function called before a log request is sent to the server. Lets you set request headers, etc (details).

Logger level and appender level

Notice that both loggers and appenders have a level. This means that a log message must have a severity that is equal or higher than both these levels in order to be processed.

Examples

This creates an appender with the behaviour below and than attaches it to the root logger:

  • It has an internal buffer that stores at most 20 log messages;
  • Log messages with severity smaller than 1000 (TRACE) are ignored.
  • Log messages with severity equal or greater than 1000 (TRACE) and lower than 4000 (WARN) are stored in the internal buffer, but not sent to the server;
  • Log messages with severity equal or greater than 4000 (WARN) and lower than 6000 (FATAL) are sent to the server on their own;
  • Log messages with severity equal or greater than 6000 (FATAL) are sent to the server, along with all messages stored in the internal buffer.
var appender = JL.createAjaxAppender("example appender");
appender.setOptions({
    "bufferSize": 20,
    "storeInBufferLevel": 1000,
    "level": 4000,
    "sendWithBufferLevel": 6000
});

JL().setOptions({
    "appenders": [appender]
});