Logging Data on Device and Retrieving the Log

Logging data on device and retrieving the log

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

Just add this block of code in application:didFinishLaunchingWithOptions method in the app delegate file and it will create a log file in app document directory on iPhone which logs all console log events. You need to import this file from iTunes to see all console events.

Note: In the .plist file make sure that Application supports iTunes file sharing is exists and is set to YES so that you can access through iTunes.

To get Logfiles :
Launch itunes, after your device has connected select Apps - select your App - in Augument Document you will get your file. You can then save it to your disk

XGCLogger: Retrieve logs from device?

I use CocoaLumberjack (another logging framework) in my apps but the following applies to any logging framework that supports logging to a file (including XGCLogger).

Setup your logging framework to log to a file (in addition to any other destination you might need).

Then add an option to your app somewhere appropriate that lets the user submit diagnostic information to you. When the user chooses this option your app can use MFMailComposeViewController to send you an email. Pre-populate the "to" field with your email address. Add the log file(s) as attachments to the email. Set the subject as desired (something like "MyCooApp Diagnostic Info"). You can also pre-populate the email message with additional details. I include the user's locale and timezone, the device name and model, and the version of iOS.

The user can add any additional info to the email message and tap Send. You get a nice email with the logs and other details.

If you don't want to take the email route, setup your web server with a special page that accepts file posts. Then have your app post the log files to your web server when the user chooses the "submit diagnostic info" option in your app.

How to get Device Logs in a text file from NSlog using Objective c?

I used this code to fix my issue

[[DBHelper getSharedInstance] AddLogFile:[NSString stringWithFormat:@"Sync Json:%@",jsonStr]];

which sends the NSLog to my device log file.

how to see iOS device logs in Console app using os_log

This is not a complete answer, but a large part of the trick seems to be this:

In Xcode's Devices and Simulators window, locate the device and show the console display by tapping the tiny button at the lower left.

Sample Image

It appears that this somehow opens the floodgates and allows the stream of log events to pass through to the Console app. It still isn't 100% reliable; eventually the stream can be mysteriously shut off, and I have the impression that events are randomly omitted now and then. But it seems to be a sine qua non for getting the stream to flow at all.



Related Topics



Leave a reply



Submit