Logging data on device and retrieving the log Logging data on device and retrieving the log ios ios

Logging data on device and retrieving the log


In Xcode 6.1.1, you can view the NSLog output by doing the following. However, I'm not sure if it lets you see logs from too far back in time. I've only seen it go back up to a couple hours.

In any case, here are the steps:

  1. In Xcode, go to Window -> Devices.
  2. Select your device in the left panel.
  3. Click the little arrow as shown in the screenshot below.

enter image description here


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


In swift 3.0, the code of Shyl will changes to,

var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)let documentsDirectory = paths[0]let fileName = "\(Date()).log"let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)freopen(logFilePath.cString(using: String.Encoding.ascii)!, "a+", stderr)

all other process are same that explained by Shyl

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