views:

4906

answers:

5

Is there some standard way or has anyone written something that allows you to log a message and have it be displayed either in a small scrolling section on the iphone screen or in a separate window in the iphone simulator?

Update: For noobs like me and don't know, use the NSLog methods as decribed below and make sure you select Run->Console to display the console.

Would still like to know if anyone has written a simple logger that displays on the iphone itself....

+3  A: 

Use NSLog(@"Log message");

+7  A: 

The Objective-C (more correct, really) method is

NSLog(@"message");

But the standard C method will work also

printf("message");
adam
It's never too early to get in the habit of: NSLog(@"%@",@"message");When you refactor later or cut and paste it will be harder to introduce a format-string bug.
Brad Smith
+10  A: 

Hi Nevster,

I don't have enough 'reputation' to add a direct comment for your posting but: don't forget to go to XCode->Preferences->Debugging->On Start: Choose Show Console & Debugger

You can of course choose just the Console or whatever, but you'll probably want the Debugger to. To use that, just click to the left of the line you want to break at. You can also toggle from 'Activate' to 'Deactivate' so you if you know that there are a bunch of breakpoints you don't need to hit in the beginning of your application set the debugging to Deactive (in the debugging window) and then, before you hit the UI element in your app you want to debug, toggle that same button to Activate so your breakpoints become active. Otherwise, you could of course just click Continue until you got to your section.

Also, on the NSLog, if you start to accumulate a bunch of log statements, and you need to 'find' one in particular, it helps to do: NSLog(@"\n\n\nMy statement\n\n\n); which will give a bunch of line breaks. Also, for the uninitiated:

NSLog(@"My int: %d my BOOL: %d", myInt, myBOOL);
NSLog(@"My object of any NSObject: %@", anObjectOfAnyKind);
NSLog(@"My float: %f",myFloat);

Hope all of this is helpful and sorry if I got off track with the debugging bit ;)

Rob
All good info - thanks!
nevster
A: 

THANK YOU !

+2  A: 

If your have an application that is crashing then your can ask the users you the crash log. The crash log contains information about what the application was doing when it crashed and the stack trace.

iPhone app log files are also stored on your users computer, and are copied across everytime they sync their iPhone. ( Note that DEVICE_NAME will be the same name of your iPhone in iTunes, and each log file will begin with the name of the app. )

Mac OS X : /Library/Logs/CrashReporter/MobileDevice//

Windows XP: C:\Documents and Settings\Application Data\Apple computer\Logs\CrashReporter\

Windows Vista: C:\Users\AppData\Roaming\Apple computer\Logs\CrashReporter\MobileDevice\

Wenzi
Does the console log also get copied over?
mahboudz