STeN
STeN

Reputation: 6268

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

Upvotes: 0

Views: 448

Answers (3)

QED
QED

Reputation: 9923

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

Upvotes: 1

Sailesh
Sailesh

Reputation: 26207

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
}

Upvotes: 2

ZhangChn
ZhangChn

Reputation: 3184

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

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

Upvotes: 1

Related Questions