zoukankan      html  css  js  c++  java
  • 使用 PLCrashReporter 上传崩溃日志, symbolicatecrash 分析日志

    集成 PLCrashReporter 上传日志

    PLCrashReporter 是开源的,官网地址:https://www.plcrashreporter.org/

    把 CrashReporter.framework 引入集成到项目中,

    implementation AppDelegate
    
    -(void)handleCrashReport {
        PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
        NSData *crashData;
        NSError *error;
        
        crashData = [crashReporter loadPendingCrashReportDataAndReturnError:&error];
        if (crashData == nil) {
            NSLog(@"Could not load crash report: %@", error);
            [crashReporter purgePendingCrashReport];
            return;
        }
        
        /* CrashData 可以直接上传到服务器上,下面的代码是保存到 Document 中 */
        NSArray *docPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *docPath = [docPathArray firstObject];
        NSString *path = [docPath stringByAppendingString:@"/crashdata.crash"];
        [crashData writeToFile:path atomically:YES];
        
        PLCrashReport *report = [[PLCrashReport alloc] initWithData:crashData error:&error];
        if (report == nil) {
            NSLog(@"Could not parse crash report: %@", error);
            [crashReporter purgePendingCrashReport];
            return;
        }
        
        /* CrashData 还需要用 PLCrashReporter 的工具 crashutil 解析,也可以直接保存成字符串*/
        NSString *humanReadable = [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS];
        NSLog(@"Report: %@", humanReadable);
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
        NSError *error;
        if ([crashReporter hasPendingCrashReport]) {
            [self handleCrashReport];
        }
        
        if (![crashReporter enableCrashReporterAndReturnError:&error]) {
            NSLog(@"Warning: Could not enable crash reporter: %@", error);
        }
    }    
    
    

    可以用 PLCrashReporter 收集到 crashData,然后用 PLCrashReporter 的工具转换为正常的 .crash 文件,在 Terminal 中的命令如下(./ 是必须要带的,哪怕已经 cd 到当前文件夹):

    ./plcrashutil convert --format=iphone example_report.plcrash > app.crash
    
    

    也可以直接用 [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS] 生成的字符串保存为 .crash 文件。

    symbolicatecrash 分析

    当获得到 .crash 日志后,就需要分析然后定位到具体的哪个文件的哪一行代码了,使用 symbolicatecrash 即可,这里有一篇教程:使用 symbolicatecrash 分析 .crash 文件

    export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"

    ./symbolicatecrash report.crash AppName.app.dSYM > 1001.crash

  • 相关阅读:
    python---RabbitMQ
    Apicloud学习第四天
    Apicloud学习第三天——获取云数据库的数据方法
    APICloud学习第二天——操作云数据库
    font-spider问题【已解决】
    Apicloud学习第一天
    sass补充(2019-3-9)
    sublime中编译的sass如何改变css输出风格?【这里有答案】
    SEO总结
    Sass学习第一天
  • 原文地址:https://www.cnblogs.com/1oo1/p/4462649.html
Copyright © 2011-2022 走看看