Documentation Menu

Configuring JSNLog using client code

Client side configuration methods

The jsnlog.js library has several configuration methods:

Making sure jsnlog.js has loaded when running configuration code

In some scenarios, such as with AMD modules, you can't always be sure when jsnlog.js and your JavaScript configuration code actually load. If your configuration code loads before jsnlog.js, that configuration code will obviously not work.

The solution is to put your configuration code in a global method called __jsnlog_configure. After the jsnlog.js library has loaded, it checks whether there is a global function with that name, and if there is, executes it.

Your configuration code would look like this:

__jsnlog_configure = function (JL) {
    ... configuration code
}; 
try { __jsnlog_configure(JL); } catch(e) {};

This solves the race condition:

  • If your configuration code loads after jsnlog.js, it is normally executed.
  • If your configuration code loads before jsnlog.js, there will be an exception, which is swallowed by the try ... catch.

    Then when jsnlog.js loads, it calls __jsnlog_configure and now your configuration code will run successfully.