JSON Log Message Format
The .Net and NodeJS editions of JSNLog include a server side end point that receives log messages. If you do not use these editions however, you'll have to create your own end point. To make that easier, this page describes:
The URL where jsnlog.js sends log messages to
The built in AJAX appender by default sends all log messages to this url:
/jsnlog.logger
You can change this using the
defaultAjaxUrl
field in the
JL
setOptions Method
Format of the log messages
The AJAX appender sends log requests with:
- A JSON string containing most of the log data;
- A request header JSNLog-RequestId containing the request id.
JSON string
The JSON string has this format:
{ r: "request id", // Obsolete. May be empty string. lg: [ { l: level, m: 'message', n: 'logger name', t: timestamp, u: event id }, ... ] }
Please note that a single JSON message to the server can contain multiple log messages. This is because the AJAX appender can be configured to batch messages, for example 2 log messages per JSON message to the server.
About the individual fields:
Field | Description |
---|---|
request id | Obsolete. Do not use. |
level | Numeric severity of the log message. |
message | Message to be logged. |
logger name | Name of the logger. |
timestamp | The time the message was logged by your JavaScript. This is the number of milliseconds since 1 January 1970 00:00:00 UTC, according to the client machine's clock. |
event id | Number that uniquely identifies the event within the request. |
JSNLog-RequestId request header with request id
The request id is used to identify all log requests that were generated by the same user.
To use this facility, set the request id in your JavaScript after the page has loaded to some unique string, using
the JL
setOptions Method
The jsnlog.js library then includes that request id in all log requests.
If you don't set the request id, jsnlog.js uses the empty string.
The request id is sent in a custom HTTP request header, JSNLog-RequestId. This way, server side code can easily determine whether a request is a log request from jsnlog.js, or some other request (such as a simple page request).