How to get source code line from stack trace in obj-c / ios

后端 未结 4 1413
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 06:31

I use NSSetUncaughtExceptionHandler to print the stack trace to local file in iPhone, which will be sent to our server next time the app launches. Then I can examin

4条回答
  •  梦毁少年i
    2021-02-05 06:47

    I don't know how to get line numbers from stack traces (yet), but at some points in my code where I want to get line number printed I used the have the following code fragment:

    NSLog(@"%s line=%d", __func__, __LINE__);
    

    which will give the following output:

    2013-04-01 00:16:46.393 MyApp[847:c07] -[AppDelegate application:didFinishLaunchingWithOptions:] line=29
    

    If you're familiar with the Log4J framework I'ld suggest to take a look at the Lumberjack framework which proves to be very helpful for me in various projects.

    https://github.com/robbiehanson/CocoaLumberjack
    

    Although this may not directly answer your question, its just meant as a reminder.

提交回复
热议问题