Logging data on the device and retrieving the log

In a debug build in Xcode, whether I use a simulator or an actual device, the console commands NSLog, printf, fprintf assert and NSAssert go to the console

If I now launched the release build on the device (let's say I send the build of test flights and increase it on my iPhone, this will be the release build), which ones (if any) are recorded?

And how do I get a magazine?

Does NSLog really output something in the release build? What is the determining factor? Will you write on stdout or stderr? Is only stderr written to the device log? Does this mean that I should use fprintf? NOTHING is written to the device log? is there such a thing? If so, how to raise it?

Can someone clarify the situation?

+63
ios logging xcode console device
Feb 01 2018-12-01T00:
source share
9 answers
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 to the application:didFinishLaunchingWithOptions method in the application:didFinishLaunchingWithOptions delegate file, and it will create a log file in the application document directory on the iPhone, which logs all console log events. You need to import this file from iTunes to view all console events.

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

To get the log files: Launch itunes, after your device is connected, select "Applications" - select your App-in Augument Document, you will receive your file. Then you can save it to your disk

+77
Nov 09 '12 at 6:17
source share

In Xcode 6.1.1, you can view the NSLog output by doing the following. However, I'm not sure if it allows you to see the magazines too far back. I only saw that it was back for a couple of hours.

Anyway, here are the steps:

  • In Xcode, go to Window -> Devices.
  • Select a device in the left pane.
  • Click the small arrow as shown in the screenshot below.

enter image description here

+134
Jan 07 '15 at 17:08
source share

In Swift 3.0, the Shyl code will be changed 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 processes are the same as Scheel explained

Just add this block of code to the application: the didFinishLaunchingWithOptions method in the application delegate file, and it will create a log file in the application’s document directory on the 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 Application supports iTunes file sharing and YES installed for it so that you can access it through iTunes.

To get the log files: Launch iTunes, after your device connects, select "Applications" - select the application - in the "Augument Document" you will receive your file. Then you can save it to your disk

+18
Jan 19 '17 at 11:48 on
source share

NSLog is written to the device log in the production version, and you can verify this by connecting your iPhone to your system and using Organizer. Select your iPhone in the organizer, click on "Device Logs". You will see all the NSLog exits in the log.

+11
Feb 01 2018-12-12T00:
source share

I found this link from APPLE very informative and complete. This pretty much gives you every opportunity to view or access device logs, whether they are connected to your dev machine or not.

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

+6
Apr 10 '14 at
source share

Yes, the NSLog outputs on the device. You can see that you are outputting it to your device connected to your Mac and using the Xcode Organizer tool.

+2
Feb 01 2018-12-12T00:
source share

If you use the Testflight SDK, you can record all the logs using the Remote Logging feature .

+2
Feb 01 2018-12-12T00:
source share

I know this is an old branch, but you can also access the device logs located at:

Settings → Privacy → Analytics → Data

Hope this helps

respectfully

0
Jan 22 '18 at 18:48
source share

I think in Xcode 9.3 the device log screen has been moved to a new location. Please follow the link below.

Get device logs at runtime in Xcode

0
Apr 27 '18 at 9:55
source share



All Articles