user3385845
user3385845

Reputation: 491

Issue with client-side log capture

I am trying to use the client-side log capture feature provided by worklight 6.1 as shown at: http://pic.dhe.ibm.com/infocenter/wrklight/v6r1m0/topic/com.ibm.worklight.dev.doc/devref/c_client-side_log_capture.html

I did the following:

  1. I set the following init options:

    var wlInitOptions = { analytics : { enabled: false } };

  2. I created an HTTP adapter called "WLClientLogReceiver" which has a log procedure as specified in the above referenced infocenter page. The log procedure is defined the same way as specified by the infocenter page:

The log procedure has the same implementation as on the infocenter with the exception of a call to WL.Logger.info() to show the log procedure is invoked on the server side:

function log(deviceInfo, logMessages) {
    WL.Logger.info("Received device logs");
    return true;
}
  1. Somewhere in the application, WL.Logger.info("...") is called a number of times.

  2. The application has button which will call WL.Logger.send() when the button is clicked.

But in the test, I don't see the client logs being written to the server log. And I don't see the output of the WL.Logger.info("Received device logs"); call indicating WL.Logger.send() is not invoking the lop adapter procedure.

What's the resolution to this issue? Or is my understanding wrong that WL.Logger.send() will invoke the log procedure?

Upvotes: 0

Views: 637

Answers (2)

Rajesh Madhu
Rajesh Madhu

Reputation: 679

logger : {enabled: true, level: 'debug', stringify: true, pretty: false, tag: {level: false, pkg: true}, whitelist: [], blacklist: [], nativeOptions: {capture: true}}

You have to enable the native capture as true in initOptions.js.

You can log using your package that will help you in filtering the messages based on the package in your WLClientLogReceiver adapter.

var myloggerObject = WL.Logger.create({pkg: 'mypackage'});
myloggerObject.debug("Hello world");

you can specify your level in your js file to be logged in client device.

In the adapter you will get the log messages as an json array. function log(deviceInfo, logMessages) {

/* The adapter can choose to process the parameters, for example to forward them to a backend server for safekeeping and further analysis.

The deviceInfo object may look like this: { "appName": "wlapp", "appVersion": "1.0", "deviceId": "66eed0c9-ecf7-355f-914a-3cedac70ebcc", "model": "Galaxy Nexus - 4.2.2 - API 17 - 720x1280", "systemName": "Android", "systemVersion": "4.2.2", "os.arch": "i686", // Android only "os.version": "3.4.0-qemu+" // Android only } The logMessages parameter is a JSON array that contains JSON object elements, and might look like this:

    [{
      "timestamp"    : "17-02-2013 13:54:23:745",  // "dd-MM-yyyy hh:mm:ss:S"
      "level"        : "ERROR",                    // ERROR||WARN||INFO||LOG|| DEBUG
      "package"      : "your_tag",                 // typically a class name
      "msg"          : "the message",              // a helpful log message
      "threadid"     : 42,                         // (Android only)the current thread
      "metadata"     : { "$src" : "js" }           // metadata placed on the log call
}]
*/

//sample log and filtering method

var logs= [{
  "timestamp"    : "17-02-2013 13:54:23:745",  // "dd-MM-yyyy hh:mm:ss:S"
  "level"        : "ERROR",                    // ERROR||WARN||INFO||LOG|| DEBUG
  "package"      : "your_tag",                 // typically a class name
  "msg"          : "the message",              // a helpful log message
  "threadid"     : 42,                         // (Android only)the current thread
  "metadata"     : { "$src" : "js" }           // metadata placed on the log call
},
{
  "timestamp"    : "17-02-2013 13:54:23:745",  // "dd-MM-yyyy hh:mm:ss:S"
  "level"        : "ERROR",                    // ERROR||WARN||INFO||LOG|| DEBUG
  "package"      : "mypackage",                 // typically a class name
  "msg"          : "my package message",              // a helpful log message
  "threadid"     : 42,                         // (Android only)the current thread
  "metadata"     : { "$src" : "js" }           // metadata placed on the log call
}

];

var filteredLogs = logs.filter(function(log){
       if(log.package == mypackage) //comparing the package and returns the object
            { return log; }   
});

WL.Logger.error(filteredLogs);// This is send only the filtered array to your server

}

If you log using metadata such as filename along with the debug message you will get those in the array in metadata attribute.

It is suggested to stringify and parse the object to avoid errors before parsing the device logs in the adapter.

var logs = JSON.stringify(JSON.parse(logs));
var filteredLogs = logs.filter ...

Upvotes: 0

mikerott
mikerott

Reputation: 423

First, your #1

var wlInitOptions = { analytics : { enabled: false } };

Is not relevant for debug log capture.

I suspect that log capture is turned off in your application.

In a default generated Worklight application, the initOptions.js file has the following:

logger : {enabled: true, level: 'debug', stringify: true, pretty: false,
    tag: {level: false, pkg: true}, whitelist: [], blacklist: [],
    nativeOptions: {capture: false}},

Notice nativeOptions: {capture: false}}. If you have run your app at any point with that initOptions object in place, then log capture has been turned off. You will need to turn capture back on by restoring the initOptions object with a true value, or by calling

WL.Logger.setNativeOptions({capture: true});

or exercising the equivalent native logger API directly to turn capture back on.

Upvotes: 1

Related Questions