Documentation Menu

setOptions Method

Sets library wide options


setOptions(options: any): void


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


The JSON object can have the following fields:

Field Type Default Description
bool true If false, all loggers are disabled.
number no maximum Limits total number of messages sent to the server. See remarks below.
string see remarks Default url used by ajax appenders when no url is set. See remarks below.
string (empty) The IP address of the browser. Used with the ipRegex option of loggers and appenders.
string (empty) Sent with all log messages to the server, so make it easier to identify all log messages for a given request. Reported via the %requestId placeholder of the serverSideMessageFormat attribute of the <jsnlog> / JsnlogConfiguration configuration element.
string (empty) Sets a beforeSend method for all Ajax Appenders.
string see remarks Method used to turn objects into strings. See remarks below.


Provides the default url if no url is set on the AjaxAppender setOptions Method. Also sets the url for the default appender.

If defaultAjaxUrl is not set, the url /jsnlog.logger is used.

maxMessages and buffering

You use maxMessages to limit the number of messages sent to the server. When you set maxMessages via a call to setOptions, a counter is set to maxMessages. Each time messages are sent to the server, that counter is decremented by the number of messages sent. When the counter gets to zero or below, no more messages will be sent.

However, this is affected by batching and buffering.

Take a situation where maxMessages is set to 5 and 2 messages have already been sent - so the message counter is now 3. If 8 messages had been stored in a buffer and those messages are now sent, they will be all sent. That means the server will receive a total of 2 + 8 = 10 messages. After this, no more messages will be sent, because the number of messages sent (10) exceeds maxMessages (5).

This means that maxMessages is not a precise limit on the number of messages sent to the server. On the other hand, buffered messages are sent together in a single request to the server, minimizing bandwidth. And buffered messages are often useful in solving exceptions, so there is value in receiving them.


When you log an object, it needs to be turned into a string. This field lets you set the method used to do this.

If you do not set this field, by default the standard method JSON.stringify is used.

Your method has to take the object as a parameter and return the string:

serialize(object: any): string

A major reason to use your own method is to deal with objects with cyclic references. That is, objects that refer to themselves (details).


This sets the requestId to be sent with all log messages to the server.

    "requestId": "35F7416D-86F1-47FA-A9EC-547FFF510086"