I'm finding it incredibly slow to fix issues that are specific to the iOS portion of my app. I'd like the know the recommended way to debug Worklight apps when the browser debugger isn't available.
In particular, I'm working on issues with WL.JSONStore which only works on iOS and Android. I can't use the browser debugger to see what's going on. When I do WL.Logger.debug() statements, nothing is showing up in the Xcode console, and the iPad simulator console (Cordova) only displays a few lines. There have also been periods this week that no output is printed anywhere.
I have downloaded and installed Weinre too, but none of the print statements appear to show up in its console and in general I just don't see information about the areas I need.
Thanks in advance for your suggestions.
General Worklight 5.0.6 Debugging
Debug Tips for JSONStore on Worklight 5.0.6
console.log('message')
orWL.Logger.debug('message')
insidejsonstore.js
and your code ([app-name].js
, etc.). The output should show up in Xcode's console and Android's LogCat.WL.JSONStore.destroy()
.WL.JSONStore.init
orWL.JSONStore.initCollection
).Look at the SQLite Database file generated by JSONStore. This only works if encryption is off.
Android:
iOS
Try looking at the searchFields with
.schema
and selecting data withSELECT * FROM [collection-name];
. To exitsqlite3
type.exit
. Take a look at this StackOverflow question for an example.(Android Only) Enable verbose JSONStore.
(iOS >=6.0 and Safari >=6.0 Only) Try to use the JavaScript debugger. Set break points inside
jsonstore.js
. Helpful lines:Bridge to Native code:
Success Callbacks returning from Native code:
Failure Callbacks returning from Native code:
Write Proper Tests (Unit, Functional, Integration -- get test coverage). Here's a template that uses QUnit and Sinon.js to create a Sandbox environment where you can test how JSONStore handles different types of data/calls:
Expected output of the code above:
Side-note: Here's a general article about the PhoneGap/Cordova workflow for a specific developer. There's a part of debugging, just browser-based though. Some of it applies to IBM Worklight development too.
cnandreu provides great tips here. Still, visibility is pretty poor and these approaches didn't really solve my problem. I would like to also suggest what I've found to be most useful in my project (aside from WL.Logger.debug() everywhere):
JSConsole has been indispensable (http://jsconsole.com/). In reality, I don't actually use it that much like it's intended. However, I've found that it's startup warning message does something with WL.Logger.debug() (and console.log()) that enables the statements to actually print to the console so I can see what I'm doing.
In iOS 6 Safari on the Mac lets you inspect the DOM of an attached device. It's moderately useful, especially for hybrid UI issues that only are misbehaving when running natively on iOS. I don't find it super helpful otherwise. See more at https://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/DebuggingSafarioniPhoneContent.html
The single most useful technique I've been using has been to write status messages to the UI. Yes, it's an ugly prehistoric way to do things, but everything else - including 80s error print statements to the console - have failed miserably. Here's what I do (using Dojo & JavaScript):
var v = dom.byId('audio_status'); if (v) { v.innerHTML += "recording file ["+filename+"]"; }
Where
audio_status
is theID
of a DIV that displays the debug content.This stuff is ugly, but at least we can see something.