简体   繁体   中英

Getting debug logs - iPhone

On Android I am using the android.util.Log to log within my application and during development I am using the adb logcat or Eclipse to see the logs - I use it even more then debugging...

On device I can save the logfile from my code or use some application form Android Market to save the logs - eg aLogCat .

Now can I do the same on the iPhone? I can use the NSLog(@"message"); , but can I easily save the log file from my application and access it? Are there any ways for that?

Regards, STeN

This is from NSFoundation reference

NSLog:

Simply calls NSLogv, passing it a variable number of arguments.

NSLogv:

Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there. If you want to direct output elsewhere, you need to use a custom logging facility.

Thus, it is only a matter of redirecting the file-descriptor "stderr" (2) to a custom file, and you will get everything that you print using NSLog in that file.

This seems to be exactly what you want.

Note that if you want to get logs on console when you are connected to the debugger, you can wrap your code around this to avoid redirection in this case:

if (!isatty(STDERR_FILENO)) { // Not connected to any terminal
    // your redirection code
}

You can access the console log from Organizer->Device->Your device->console.

If that is not powerful enough, consider using utilities like NSLogger .

The previous answers are good; also see this if you're inclined to making system calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM