0

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

STeN
  • 6,262
  • 22
  • 80
  • 125
  • I think the logs are written to a part of the disk that your app isn't allowed to read from. You can get your beta testers to send the to you manually. And I believe apple might send you crash logs sent to them by users as well? Not sure. It probably contains private data anyway, you would be in breach of apple's app store terms if you send it to a remote server without the user's permission. – Abhi Beckert Feb 28 '12 at 07:09

3 Answers3

2

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
}
Community
  • 1
  • 1
Sailesh
  • 25,517
  • 4
  • 34
  • 47
  • Very good - now we can redirect logs from console to file and access it from iTunes - pretty similar to the Android way. Thanks – STeN Feb 28 '12 at 09:23
1

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

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

ZhangChn
  • 3,154
  • 21
  • 41
1

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

Community
  • 1
  • 1
QED
  • 9,803
  • 7
  • 50
  • 87