Registrar datos en el dispositivo y recuperar el registro

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?

preguntado el 01 de febrero de 12 a las 14:02

For just save the outputs as File use this: stackoverflow.com/questions/28114110/… -

9 Respuestas

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

Respondido el 07 de enero de 15 a las 20:01

This should be the correct answer... I spent half an hour to look for the log button. Thanks for saving my time... - Primaria Pollo

just NSLog. Don't expect cout or printf there. - kiranpradeep

You cannot get the logs from production/submitted apps using this technique. Its useful only while debugging. - Satyam

you made my day, perfect example how NOT to design UI maybe they should read developer.apple.com/library/mac/documentation/UserExperience/… - Hofi

You just saved my bacon. Have been chasing a bug that only appears in release version, logs revealed the issue. I had looked at that same dialog and never thought to click the small arrow, which is apparently a universal symbol for "show live device logs". Thank you! - chacmool

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

Respondido el 10 de junio de 16 a las 13:06

How does this work? just by having a .log file in the documents directory iOS writes your console output there? - Ali

How to delete log files programmatically by date order to prevent leak disk memory? - hkaraoglu

No estoy seguro si NSDocumentDirectory is appropriate for log files - it is usually meant for user's own generated content, but log files are app support content, therefore maybe they belong in NSLibraryDirectory /Logs subdirectory. - JustAMartin

¿Cómo puedo exportar los detalles del registro desde una PC con Windows? - Vineesh TP

@Ali it works by associating the stderr (standard error output) file descriptor (i.e. file descriptor 2) to a file open for writing. So every time you print to stderr, it prints to the file instead. That way, you catch the stderr output of the application. The log system knows nothing about it. - Munición Goettsch

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

Respondido el 13 de diciembre de 18 a las 19:12

correct me if I'm wrong: This cambios the directory of the logs meaning it's originally written in /var/db/diagnostics/. Ver aquí. - MIEL

@Honey , this log will saved in the app document directory. - Kiran P Nair

This code always create a new file when app launched - DURGESH

Any idea how to get this to work when the log is executed within a Watch Extension? - user2623825

@KiranPNair - can I do this for print() statements as well or just NSLog? - Fra

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.

Respondido 01 Feb 12, 18:02

Update: In Xcode 6 it is no longer possible to read the NSLog outputs via the Device Logs. Window > Organizer no longer lists the devices. Instead Window > Devices lists the devices, but only displays the crash logs. - Robert

Robert, on Window > Devices screen of Xcode 6 there is an invisible line near the bottom edge of the screen. If you pull it up you'll see the console log of your selected device. It is invisible because of an UI bug in Xcode I think. - oradyvan

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

Respondido 10 Abr '14, 18:04

This document is amazingly out of date. It only mentions xCode 6. The method is completely different for xCode 9 and 10 - 1800 INFORMACIÓN

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

Respondido 01 Feb 12, 18:02

Is it possible for a user to inspect these logs through iTunes? - Pi

Esta respuesta stackoverflow.com/questions/2334664/… is stating iPhone Configuration Utility is possible to export console log from device - Denis

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

contestado el 29 de mayo de 13 a las 02:05

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

Settings -> Privacy -> Analytics -> Data

Espero que esta ayuda

saludos

Respondido el 22 de enero de 18 a las 21:01

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

Respondido 27 Abr '18, 12:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.