Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: How to read application logs from device

Tags:

logging

iphone

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

like image 419
zohar Avatar asked Mar 03 '11 09:03

zohar


3 Answers

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.

like image 101
Fran Sevillano Avatar answered Oct 04 '22 16:10

Fran Sevillano


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

like image 37
zoul Avatar answered Oct 04 '22 14:10

zoul


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

like image 43
radalin Avatar answered Oct 04 '22 14:10

radalin