Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to log debug info in an iphone app?

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....

like image 321
nevster Avatar asked Dec 10 '08 11:12

nevster


1 Answers

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 ;)

like image 149
Rob Avatar answered Sep 23 '22 07:09

Rob