9

Is there a way to read the application logs from the iPhone device? Something similar to LogCat of Android?

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
zohar
  • 2,298
  • 13
  • 45
  • 75
  • Linking this question to [this][1]. [1]: http://stackoverflow.com/q/7286918/1224741 – QED Feb 28 '12 at 07:41

4 Answers4

28

As Zoul said, you could obtain them in the Organizer. But prior to that, you should tell your application to store the logs in the Documents folder, for example. That way when you are in the Organizer,extract the application data and you will find the logs there.

Now, in order to tell your app to redirect the NSLog() outputs to a file, you should do something like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];

NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];

freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);

The last sentence is the one that actually redirects the output.

So once you have done that, your app logs will be stored in the application's documents folder.

Don't you know how to extract the application data? Here you shall find out.

I hope it helps you out.

trss
  • 915
  • 1
  • 19
  • 35
Fran Sevillano
  • 8,103
  • 4
  • 31
  • 45
  • If it was helpful for you, it would be nice if you voted it up. Thanks – Fran Sevillano Mar 03 '11 at 11:35
  • This is a great solution and is exactly what we needed for developing an app that needsd to be connected to another device and still allow us to collect debug logs. Thanks Francisco. – David Potter Sep 15 '11 at 18:53
6

If you are on Linux, install libimobiledevice, connect your iPhone to your computer and run idevicesyslog | grep <your app name>. This will show you all debug info and logs from NSLog statements, just like LogCat in Android. The advantage of this method:

  1. your app doesn't have crash in order for logs to be available
  2. It can show logs from all processes, not just your app if you drop the grep
  3. Full filtering power of Linux tools like grep available
Babken Vardanyan
  • 14,090
  • 13
  • 68
  • 87
4

You can use the "Console" application in Mac to see the logs from the device.

radalin
  • 600
  • 5
  • 13
4

From the device connected to your machine? Open the Xcode Organizer (Cmd+Shift+O), click on the device, select the Device Logs tab.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • The Organizer shows only crash log while I am looking for regular logs that where written inside the app – zohar Mar 03 '11 at 11:01
  • 2
    Organizer shows the console also, which has the NSLog output. The device has to be provisioned and have settings->developer settings->Logging turned on. – Michael Aug 22 '12 at 14:53