25

I am trying to develop a basic hello world application with phonegap on Xcode. But i can not see the log messages on Xcode console. I have tried console.log and debug.log but they did not worked for me?

How can i see javascript log messages on xcode console?

Isa Kuru
  • 2,079
  • 4
  • 16
  • 12

10 Answers10

27

In Phonegap 3.0 you have to add a plugin for console.log to work in the xcode console.

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git

More info: http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface

Nick Breen
  • 293
  • 3
  • 7
  • 2
    Note, that you need to run it from your project folder and have Git for Mac installed (from here: http://git-scm.com/download/mac). – Nikolai Samteladze Nov 12 '13 at 22:14
  • 5
    I believe that most of the people using **Phonegap** have **Git** installed anyway. On my machine ```cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git``` *(Cordova 3.4.0)* – Mars Robertson Apr 06 '14 at 16:58
  • on ``https://github.com/apache/cordova-plugin-console/blob/master/doc/index.md`` they say: ``cordova plugin add org.apache.cordova.console`` which did the job for me! – Benjamin Oct 01 '14 at 16:31
10
  1. On your real iDevice or in iOS simulator go to Settings > Safari > Advanced and turn on Web Inspector.
  2. Desktop Safari: Safari > Preferences > Advanced and select the Show develop menu in menu bar checkbox.
  3. Now that you have either iOS Simulator open or your iDevice connected to your mac start using web inspector on your website: On your mac, open Safari and go to Develop
Marcel Gwerder
  • 8,353
  • 5
  • 35
  • 60
lsolano
  • 129
  • 1
  • 2
  • 1
    Much more helpful than just console messages, indeed. This also allows you to manipulate the DOM for example. See my answer [Configuring iOS and Xcode for remote debugging](http://stackoverflow.com/a/15818612/1548776) for more detailed instructions on setup. – ᴠɪɴᴄᴇɴᴛ Nov 27 '14 at 17:47
  • This isn't useful if your goal is to see javascript log messages on xcode console. – nym Aug 12 '15 at 20:00
  • Much easier and a better way to accomplish what OP wants without relying in a plugin. – CatBrownie Aug 10 '17 at 18:17
8

Phonegap has a pretty good blog post about this here.

One of the things they mention includes JSLint which I personally use a decent amount. You just post your JS code there and it'll scan for errors and good styling. I also suggest trying to put t the code in a simple html file and run it on the browser. Anything that might seem phone-related, just get rid of it. Its nice to sandbox your javascript on the browser side and then use things like Firebug or Chrome's debugger. (Also I'm sure console.log() will work there :D)

I've also seen a lot of people mention, including in the blog post, about Weinre so that is something worth checking out.

Other relevant questions that might help:

Phonegap - Javascript debugging in Xcode

iOS PhoneGap debug Workflow

How to see the javascript errors of PhoneGap app in Xcode?

Hope this helps.

EDIT: Found this recently: Debugging in Phonegap

Community
  • 1
  • 1
aug
  • 11,138
  • 9
  • 72
  • 93
4

console.log("msg here: "+var); should work. It will come out as ...[INFO] msg here: hi! (after the date, time, app, etc.).

To view the messages go to View > Debug Area > Activate Console (or shift+cmd+C)

oshevans
  • 116
  • 1
  • 7
2

As @NickBreen said, you must add the right plugin, but we also needed to wait for the deviceready event to fire before the console displayed log statements.

Crashalot
  • 33,605
  • 61
  • 269
  • 439
2

In later versions of phonegap/cordova, to add the debug console plugin in your project:

cordova plugin add org.apache.cordova.console

Naresh Ramoliya
  • 770
  • 2
  • 8
  • 25
0

In my case, i just needed to comment the following lines in the cordova.js :

if(typeof window.console === "undefined") { window.console = { log:function(){} };

0
  1. Add the Debug console plugin
  2. Add a console.log message in onDeviceReady in the sample phonegap code or code that runs after that.

Important: console messages are displayed after the 'deviceready' event. Console.log will not generate message before that.

Alex L
  • 8,419
  • 6
  • 43
  • 51
0

Problem

The following or a similar error message occurs when adding the console plugin to the ios platform (or after reinstalling) via Command-line Interface:

"CDVPlugin class CDVLogger (pluginName: Console) does not exist."

Solution

Open your Xcode project and go to the tab "Build Phases". Now open the drop-down named "Compile Sources". Click on the "+" sign at the end of the list and add "CDVLogger.m" or any other missing source.

Omnicon
  • 314
  • 2
  • 9
-1
confirm("msg here: "+var);

or

console.log("msg here: "+var);
oezi
  • 51,017
  • 10
  • 98
  • 115
samibel
  • 634
  • 2
  • 6
  • 20