Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get previous run, crash logs on iPhone

I trying to write a a crash report feature that when you launch the app after a crash, it will offer to send the crash report to the server. I can't find how to get the crash log within the app. I saw there is a framework that doing so (PLCrashReporter), however this framework is large and I don't need most of it's features.

Does anyone knows how to simply access the log?

Thanks, Guy.

like image 847
Guy Ephraim Avatar asked Nov 28 '22 10:11

Guy Ephraim


2 Answers

I guess I don't have the karma to add a comment to Nimrod Gat's answer, so I have to provide my follow-up here. I'll try to make it worthy of a standalone answer.

It's very, very difficult to write a safe, correct, and reliable crash reporter, especially one that runs directly in-process. The code referenced in Nimrod Gat's answer is not correct and honestly, that blog post should be retracted. Signal handlers must only run async-safe code, and that code isn't async-safe:

http://www.cocoadev.com/index.pl?SignalSafety

Crash handling is even more complicated than normal signal handling, because that you can't expect the process to continue to run successfully after your signal handler returns.

It's tempting to think you can just hack together a simpler solution, and it will work some of the time, but there's a good reason people like Google's engineers have thousands of LoC dedicated to reliable crash reporting:

http://code.google.com/p/google-breakpad/

On iOS, you should just use PLCrashReporter. On other platforms (such as Mac OS X) you should use Google Breakpad. There's no point in re-inventing this wheel unless you're going to do it not only correctly, but better than what already exists.

like image 68
nupark Avatar answered Dec 09 '22 10:12

nupark


I had this similar issue and the PLCrashReported seemed too complicated for what I wanted to do. Note that you can't access the crash report generated by Apple, the PLCrashReport generates it's own reports and store them in the user's cache folder.

Eventually, I used the following example: http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html

it's very simple and easy to use, just register exception and signal handlers using:

NSSetUncaughtExceptionHandler(&HandleException);
signal(SIGABRT, SignalHandler);
signal(SIGILL, SignalHandler);
signal(SIGSEGV, SignalHandler);
signal(SIGFPE, SignalHandler);
signal(SIGBUS, SignalHandler);
signal(SIGPIPE, SignalHandler);

and get the stack trace using the backtrace method in UncaughtExceptionHandler class.

like image 35
Nim Gat Avatar answered Dec 09 '22 08:12

Nim Gat