What's the best way to log debug info in an ip

2019-03-15 08:02发布

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

5条回答
可以哭但决不认输i
2楼-- · 2019-03-15 08:38

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

NSLog(@"message");

But the standard C method will work also

printf("message");
查看更多
趁早两清
3楼-- · 2019-03-15 08:48

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

查看更多
Evening l夕情丶
4楼-- · 2019-03-15 08:51

Use NSLog(@"Log message");

查看更多
虎瘦雄心在
5楼-- · 2019-03-15 08:52

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\

查看更多
我命由我不由天
6楼-- · 2019-03-15 08:59

For Swift, it's simply

print("log msg")
查看更多
登录 后发表回答