I create a project using the Cordova command line. As the target platform for the assembly, I specify only android, the application on the device starts up, everything is fine. But how to see the messages that are created using the console.log() method? For example, after creating a project, the source file Project / www / js / index.js looks like this:

 var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; app.initialize(); 

I assume that the string is console.log('Received Event: ' + id); should display the message "Received Event: ..." in the console, but I can not see it. I added the plugin cordova-plugin-console , but the messages are still not visible. When run from the command line batch log file

 Project\platforms\android\cordova>log 

there are a lot of messages in the console, but I cannot see the "Received Event: ..." messages among them (perhaps because there are too many messages, but I cannot set the logging level (debug, error, etc.) .

I added the PATH% ANDROID_HOME% \ platform-tools \ and% ANDROID_HOME% \ tools \ environment variables, tried to see the messages via adb:

 adb logcat CordovaLog:D *:S 

but it also led to nothing, in the console after this command I see only two lines:

 --------- beginning of /dev/log/system --------- beginning of /dev/log/main 

Please help me figure out: can I see this message ("Received Event: ..."), and what do I need to do? Thank you in advance.

  • ionic serve for example - Serge Esmanovich

1 answer 1

Yes you can. Everything works for me without a plugin. I use the Android Device Monitor (I’m in {android_sdk_path}\tools\lib\monitor-x86_64\monitor.exe ), filter tag:Console .

The android feature - console.log takes only one argument, i.e. console.log(1,2) you will see only 1. In addition, objects and arrays, as in the browser console, you also will not see (I use JSON.stringify , but this is not a panacea, because when studying system objects you can easily catch an error about converting circular structures to json).

Here's how it looks to me:

That's how it looks to me Filter:

enter image description here

  • I apologize, but how exactly do you use the Android Device Monitor (not for the emulator, but for the connected device)? - Ksenia
  • Added screenshots. Do not he see the device? - Darth
  • Everything turned out, thank you very much !!! - Ksenia
  • You can also adb logcat | Select-String (adb shell ps | findstr io.cordova.hellocordova).Split("", [System.StringSplitOptions]::RemoveEmptyEntries)[1] in PowerShell like this: adb logcat | Select-String (adb shell ps | findstr io.cordova.hellocordova).Split("", [System.StringSplitOptions]::RemoveEmptyEntries)[1] adb logcat | Select-String (adb shell ps | findstr io.cordova.hellocordova).Split("", [System.StringSplitOptions]::RemoveEmptyEntries)[1] (substitute app id for io.cordova.hellocordova ). - daserge