+

Search Tips   |   Advanced Search

Callback

We can pass a callback function to WL.Logger.config that will be called after every log message.

The callback takes these arguments:

If stringify : true is set, the message is a string. Otherwise it is an array. If the package is not defined, the message is an empty string.

Send all log messages to a backend using jQuery.ajax:

var ajaxSender = function (message, priority, pkg) {
    $.ajax({
        url: 'http://localhost:3000/logs'
        type: 'POST',     data: {
            message: message,         priority: priority,         pkg: pkg
        }
    });
};
WL.Logger.config({callback: ajaxSender});

Sends all log messages to a backend using a invokeProcedure method as defined in the WL.Client class.

var adapterSender = function (message, priority, pkg) {
    var invocationData = {
        adapter: 'Logger',     procedure: 'sendLogs',     parameters: [message, priority, pkg]
    }
    WL.Client.InvokeProcedure(invocationData);
};
WL.Logger.config({callback: adapterSender});

Log JavaScript errors for a specific package using the logActivity method as defined in the WL.Client class.

var activitySender = function (message, priority, pkg) {
    if (priority === 'ERROR' && pkg === 'my.app.db') {
        WL.Client.logActivity(message);
    }
};
WL.Logger.config({callback: activitySender});


Parent topic: Configure the MobileFirst Logger