Using Logcat with Cordova

I've been using Cordova to build an Android app. Since Cordova's focus is on using web technologies to build mobile I'm expecting similar debugging tools, especially in the console. The first step is to add the cordova-plugin-console this returns web console messages to the debugger.

Now all I have to do is start logcat from a command line

adb logcat

then fire up my emulator

cordova emulate android

and I get the following web console message.

06-20 08:16:53.109  3700  3700 I chromium: \[INFO:CONSOLE(56)\] "Uncaught ReferenceError: faux is not defined", source: file:///android\_asset/www/js/index.js (56)

Which is great, because on line 56 of my index.js file I'm making a call to a function called faux(); which does not exist (console.log() will return a similar message). The running Android application is telling me where in my JavaScript code the error occurred, which is what I want. The problem is that logcat is very verbose so the messages run by faster than I can read them.

I did notice one consistency in the web console messages INFO:CONSOLE so I opted for a regex filter to return only message containing the string INFO:CONSOLE. Starting logcat with the following arguments gives me a manageable console. (Replace MyApp with the name of your application)

adb logcat ActivityManager:I MyApp:V -e INFO:CONSOLE\*

Now, with the exception of a few of start-up and tear-down messages, I'm focused solely on the output of the web console.


LinkedInGitHubTwitter