Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

logging - iPhone: How to read application logs from device

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...