Documentation Menu

Lost connection handling

The browser running your JavaScript code may not always have access to the Internet. For example if somebody opened your site on a smartphone and they are travelling through a tunnel.

jsnlog.js keeps track of whether a log request to the server succeeded or failed. If it failed, it retains them in the batch buffer (which is used for message batching).

Meanwhile, if your JavaScript code keeps logging messages, they will be added to the batch buffer. So the number of messages in the buffer keeps growing while the server is unreachable.

maxBatchSize limits number of messages kept

Limit how large the buffer can grow by setting the appender option maxBatchSize (in JavaScript or on the server ) If the number of messages in the buffer reaches maxBatchSize, subsequent messages are discarded.

When the server becomes reachable again, all messages in the batch buffer are sent in one big batch. If any messages were discarded, an additional log message with severity WARN will be sent in the same batch to let you know.

sendTimeout sets time between retries

The appender option sendTimeout is the time in milli seconds after which jsnlog.js gives up waiting for a response to a log request.

After a timeout, the old log request is aborted and a new log request sent with all the messages in the buffer. That means that if message were added to the buffer while the response was outstanding, those new messages will be sent as well.

jsnlog.js may find out well before this timeout that no success response will be received. For example, it will be told immediately by the browser that the connection to the Internet is gone when it tries to send a request. However, in order to not put too much load on the device, jsnlog.js will wait sendTimeout milli seconds anyway before sending another log request.