user10461683
user10461683

Reputation:

How to programmatically get the log messages in an iOS app?

I am using methods defined in https://developer.apple.com/documentation/os/logging to log messages in an iOS app. How can I read/access the logged messages programmatically?

The user can send feedback from inside the app, if anything in my app is not working. With the feedback, I would like to attach the logged messages to the feedback so that I can find out what happened.

Is there a way I can programmatically get all the messages that were logged by my app? Is there a way I can programmatically get the log file stored in the file system?

Upvotes: 5

Views: 1601

Answers (1)

Pratik Patel
Pratik Patel

Reputation: 1421

The logs which you want to get, it is very tough and also protected.

I have a code snippet with which you can write all NSLog data into a file.

This will save all Console Log into a file and then you can get that file when your user write a feedback to you from API.

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);

Upvotes: 1

Related Questions