21

With a fresh download of Cordova 2.9 and the Cordova CLI, I created Hello World application via the CLI. I also added the iOS platform via the CLI. Looking in the index.js file (within www/js), there is a javascript object which contains the function that fires onDeviceReady, and a function inside it, which contains a console.log which should output "Received Event: deviceready".

After running this app from Xcode in the iOS 6.1 simulator, there is no output from the console.log in Xcode's debug console. I looked at the cordova.js file and noticed the CLI platform add utility added 3.0 (ran this yesterday, before the 3.0 release), but I tried running the app with cordova-2.9.0.js as well.

Anyway, I haven't been able to get a console.log in my own application or the Hello World app to display in Xcode's console with cordova 2.9 or 3. My Xcode console is set to All Output. Is this an error with the release? From all the googling I've been doing, it seems Cordova has had on and off support of console.log depending on the version and I don't know where it's supposed to be now. Thanks for your help.

inorganik
  • 24,255
  • 17
  • 90
  • 114

4 Answers4

35

The console functionality is now implemented as a plugin, which you need to manually add to your project:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
danieldkim
  • 512
  • 5
  • 6
  • Yeah, that threw me off as well. I actually entered a bug in JIRA before figuring it out. Fwiw, they do mention it in the documentation at http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface in the "Add Features" section but it's easy to miss the part about the debug console because the ability log to the console has always been a core feature and not a plug-in or add-on. – danieldkim Aug 13 '13 at 20:28
  • 4
    Could you please also explain how to use it? In older versions of cordova you could use ./cordova/log from command line. How do you access log now? – HonzaBé Aug 19 '13 at 09:39
  • 1
    @honzzz the question is about the [console.log](http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it) function in JavaScript. in Cordova, console.log will write to the appropriate console on the platform, i.e. on iOS it will write to the Xcode console. – danieldkim Aug 22 '13 at 20:30
  • For ios, the plugin seems to install in platforms/ios/plugins/org.apache(...)console/www, and in the application bundle this gets deployed as www/plugins/org.apache(...)console/www. Can you confirm? – miraculixx Sep 06 '13 at 15:59
  • This console plugin works only with Xcode on the Mac OS environment, it's good as useless for Windows developers. – andreszs Jan 11 '15 at 14:01
  • This doesn't work for me on Android 4.4.2. `console.log("my message")` doesn't show up in the output of `adb logcat`. On the other side, `alert("my message")` at the same point in the code would show the alert, so something is not working with `console.log`. – John Smith Optional Jan 09 '16 at 12:38
15

try to add Debug Console plugin to your project by running this command:

$ cordova plugin add org.apache.cordova.console
Harry
  • 87,580
  • 25
  • 202
  • 214
Hoa Hoang
  • 1,212
  • 14
  • 20
  • 8
    And then? How do you get the debugging output? – timing Mar 26 '14 at 19:38
  • 3
    adb logcat CordovaLog:D *:S – Nawal Sep 09 '14 at 16:09
  • This doesn't work for me on Android 4.4.2. `console.log("my message")` doesn't show up in the output of `adb logcat`. On the other side, `alert("my message")` at the same point in the code would show the alert, so something is not working with `console.log`. – John Smith Optional Jan 09 '16 at 12:39
1

The problem is because of the command line utility. There are two ways to create a project with the PhoneGap/Cordova CLI - Use the bash scripts that come with PhoneGap folder you download, and (2) to install the Cordova CLI.

I used the Cordova CLI, which doesn't use any resources you download, it downloads the latest release of PG - in this case 3.0, which isn't available yet on phonegap.com. It's very possible it may not be a stable release, because the console.log didn't work in the iOS app it created.

I tried using the batch script in the 2.9 folder I downloaded, and it created an app with fully functional console.log(ging).

inorganik
  • 24,255
  • 17
  • 90
  • 114
0

This turned out to be a 2 hour long problem for me so I thought I would share the love! I fresh installed Cordova 3.0 and then installed the official console log plugin with

cordova plugin add cordova-plugin-console

But I still could not get Safari to show logs by going to

Safari > Develop > IOS simulator > index.html

So I opened up Xcode and checked the system log File > New Log Window > system.log

...system.log is on the left hand side of the popup under the Files section.

There I noticed that there was a log reading

Oct 14 01:12:57 Bens-MacBook-Pro.local ios-sim[37222]: stderrPath:     
/Users/benconant/Dev/FirstCordovaApp/platforms/ios/cordova/console.log

so I ran

tail -F /Users/benconant/Dev/FirstCordovaApp/platforms/ios/cordova/console.log

in a new terminal window and boom ... got my logs!

Still have no idea how to get them from Safari :( Would welcome any hints at how to make that happen. Good luck ... this was/is a ruff one.

Benjamin Conant
  • 1,684
  • 1
  • 14
  • 17