Logging data on device and retrieving the log

IosXcodeConsoleLoggingDevice

Ios Problem Overview


On a debug build in Xcode, regardless of whether I am using the simulator or an actual device, NSLog, printf, fprintf assert and NSAssert statements come out on the console

If I now run a release build on the device (say I send a test flight build and big it up on my iPhone; this will be a release build), which of these (if any) are getting recorded?

And how do I retrieve the log?

Does NSLog actually output something on release build? What is the determining factor? Whether it is writing to stdout or stderr? is only stderr written to device log? Does this mean I have to use fprintf? Is ANYTHING written to device log? is there even such a thing? If so, how to pick it up?

Could someone clarify the situation?

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

Solution 3 - Ios

In swift 4.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

Solution 4 - Ios

NSLog is written to device log in production release and you can check this by connecting your iPhone to your system and using Organizer. Select your iPhone in the organizer, click Device Logs. You would see all NSLog outputs in the log.

Solution 5 - Ios

I found this link from APPLE very informative and complete. It pretty much gives you all the options to see or access logs of the device whether or not they are connected to your dev machine.

https://developer.apple.com/library/ios/qa/qa1747/_index.html

Solution 6 - Ios

Yes, NSLog outputs on the device. You can see it's outputs with your device connected to your Mac and using Xcode Organizer tool.

Solution 7 - Ios

If you use Testflight SDK, you can capture all logs with their Remote Logging feature.

Solution 8 - Ios

I know this is an old thread but you can also have access to the device logs going to:

Settings -> Privacy -> Analytics -> Data

Hope this help

Regards

Solution 9 - Ios

I think in Xcode 9.3 the device log screen has been moved to a new location.Kindly refer the following link.

Get device logs at runtime in Xcode

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionP iView Question on Stackoverflow
Solution 1 - IosMyxticView Answer on Stackoverflow
Solution 2 - IosshylaView Answer on Stackoverflow
Solution 3 - IosKiran P NairView Answer on Stackoverflow
Solution 4 - IosBoraView Answer on Stackoverflow
Solution 5 - IosGrandStephView Answer on Stackoverflow
Solution 6 - IosDenisView Answer on Stackoverflow
Solution 7 - IospojoView Answer on Stackoverflow
Solution 8 - IosRamón EstebanView Answer on Stackoverflow
Solution 9 - IosVaibhavView Answer on Stackoverflow