Skip to content
Chris Mowforth edited this page Sep 4, 2013 · 74 revisions

Setup

init()

You must call init to set up le.js. At a minimum you must specify a token:

LE.init('YOUR-TOKEN');

you can also change the default parameters:

Option Description Default Example
token Mandatory. The Logentries token identifier none LE.init('TOKEN') or LE.init({token: 'TOKEN'})
ssl Use SSL/TLS to send events true LE.init({token: 'TOKEN', ssl: false})
catchall Log any uncaught JavaScript exceptions. This replaces the window.onerror handler, but if you've specified one already, it'll invoke that one afterwards false LE.init({token: 'TOKEN', catchall: true})
trace Adds a randomly generated trace code false LE.init({token: 'TOKEN', trace: true})
page_info Append basic information about browser capabilities. Options are never, per-page and per-entry. See page info 'never' LE.init({token: 'TOKEN', page_info: 'per-page'})
print Echo events to the screen via the console object. This will logged at the same level as the call to LE, e.g. LE.warn => console.warn. See log levels false LE.init({token: 'TOKEN', print: true})

Tracing

When logging on the web, you don't have any knowledge of the event-generators (browsers!) ahead of time. This presents a problem: how do you group log events that originated from the same user, and how do you differentiate users? The trace_code option adds a unique string to each event, giving you a handle to search against in the Logentries dashboard.

Page info

le.js optionally lets you log basic capabilities for the originating user-agent. The data sent will look something like this:

{
    name: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us)",
    screenWidth: 1024,
    screenHeight: 768
}

You can choose to send this at the following frequencies:

  • per-page: the first time an event is logged after a page refresh
  • per-entry: every time an event is logged
  • never: not at all

Logging

With le.js configured, go log some events. log takes most of the same arguments as console.log:

log()

LE.log("Hello, logger!"); // Simple string-literal

var x = "logger";
LE.log("Hello, ", x, " and some objects: ", 1); // Interpolation

LE.log({hello: "logger!"}); // Object (gets logged as a key=value pair)

// An object with some nesting
LE.log({nested:
    {object: [1,null],
     key: undefined}
});
// => nested.object.0=1,nested.object.1=null,nested.key=undefined

Format

  • Simple JS types (numbers, string literals and booleans) are left untouched
  • null and undefined values will be explicitly printed as strings for clarity (unlike, say, JSON.stringify())
  • Objects and arrays are 'flattened' to make them searchable; see the examples above

Log levels

le.js supports the following methods to log events at different severity levels:

  • log
  • info
  • warn
  • error

They otherwise behave exactly the same as log():

LE.log("a LOG level event");
LE.info("an INFO level event");
LE.warn("a WARN level event");
LE.error("an ERROR level event");
Clone this wiki locally