2

When my app crashes, I would like to save the latest console for debug purposes (especially to read system messages such as unrecognized selector)

Is it possible to access the console programatically?

UPDATE:

I've found the answer in the documentations: using STDERR_FILENO.

"Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there."

Gilad Novik
  • 4,546
  • 4
  • 41
  • 58

2 Answers2

2

It sounds like you want to change the destination for the standard output stream. I've never tried that in iOS, but I'd expect to be able to do that using freopen(). Here's a SO question that may help.

You'll also want to build some debug feature into your app that makes it easy to recover the output. You could post it to a web server, for example, or have the app e-mail it to you.

Community
  • 1
  • 1
Caleb
  • 124,013
  • 19
  • 183
  • 272
  • It didn't work for the default NSLog messages. It did create the file, but it's empty and all messages still show in the console. I guess NSLog is using a different approach :( – Gilad Novik Aug 01 '11 at 21:43
  • 1
    Actually, you were right :). I was redirecting stdout. When I've tried to redirect stderr - it works. Thanks! – Gilad Novik Aug 01 '11 at 21:50
  • @Gilad did you publish to AppStore with freopen in your code? Were there any problems with review? I want to redirect all output of my app to /dev/null. I'm afraid that Apple can reject my app for such use. Please take a look at http://stackoverflow.com/questions/32780617/ios-suppress-output-with-freopen-will-it-pass-apple-review – Petr Sep 25 '15 at 12:36
0

When your app crashes in a device, a crash log is saved. When you plug your device in, launch XCode, open the "Organizer" window and click on devices. Then look for your device on the left, and click on "crash logs." Together with the information from the .dSYM file that's generated when you build, you can often recover how and where your app crashed. If you really just want to save the information in the console window of XCode when you crash, just click inside the console window, hit Cmd-A (select all), and Cmd-C (copy), then paste into a text editor window.

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
  • I'm do have a crashlog for my app, but I also want an access to the console since sometimes it contains useful information related to the crash. – Gilad Novik Jul 19 '11 at 23:27