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

  • 相关阅读:
    读取INI配置文件
    在VB编程中,若一行代码太长需要换行时,行尾要加什么符号
    使用order by和group by的分析
    转 Sqlserver_left join 、right join、 inner join 用法
    Python 字典(Dictionary)操作详解
    转sql server新增、修改字段语句(整理)
    Winform TextBox中只能输入数字的几种常用方法(C#)
    数据库的范式,第一、二、三、四、五范式、BC范式
    【操作系统】银行家算法
    转 图解排序算法(三)之堆排序
  • 原文地址:https://www.cnblogs.com/1oo1/p/4462649.html
Copyright © 2011-2022 走看看