Logging - GibraltarSoftware/Gibraltar.Agent.Web.JavaScript GitHub Wiki

Logging

As per the .Net agents the agent has the same methods to allow you to send a log message to the server:

  • verbose
  • information
  • warning
  • error
  • critical
  • write

With the exception of the write method the methods support the following arguments:

  1. category
  2. caption
  3. description
  4. parameters
  5. exception
  6. details
  7. methodSourceInfo

The write method differs in that it has additional parameter, severity, which is its first parameter and needs to be supplied by yourself from the object literal loupe.logMessageSeverity, or logService.logMessageSeverity in the angular agent, the other methods will supply the severity themselves

Parameters

category

The application subsystem or logging category that the log message is associated with, which supports a dot-delimited hierarchy.

caption

A simple single-line message caption. (Will not be processed for formatting.)

description

Additional multi-line descriptive message (or may be null) which can be a format string followed by corresponding paramters.

parameters

A variable number of arguments referenced by the formatted description string (or no arguments to skip formatting).

exception

An Exception object to attach to this log message.

details

A JSON or XML document (as a string) holding any additional information you may want to include.

methodSourceInfo

A loupe.MethodSourceInfo object that holds details on file, method, etc where the log message was called from

Logging a message

Since JavaScript does not support method overloading there is only one method definition but you can provide as many, or as few, paramters as you wish.

In general any parameters you do not supply will be set to null and details will not be logged on the server when it receives the message.

To log a message you call the appropriate method providing the information you wish to log e.g. (examples from Native Agent)

  • Logging startup up of client - loupe.information("Client","Startup")
  • Logging details of validation failure - loupe.warning("Client","Invalid Address","User entered invalid address: {0}","I live here")
  • Logging custom exception -

    var customError = new Error("caught exception");

    loupe.error("MyClient","Caught exception","Caught exception performing logic", null, customError);