程序中引入crash日志文件
来源:互联网 发布:网络咨询护士压力大吗 编辑:程序博客网 时间:2024/05/05 05:53
看安卓crash后都有什么crash日志文件,直接就锁定在哪crash,为什么crash,感觉不错,自己也摸索一下,在iOS程序中我也写了一个crash日志文件,便于更好的监测和修复项目。我在程序入口的时候写入下边的代码:
//异常处理函数
static NSString* CRASHLOG_PATH = @"__pbmobilecrash.log";
void UncaughtExceptionHandler(NSException *exception) {
NSArray *arr = [exception callStackSymbols];//得到当前调用栈信息
NSString *reason = [exception reason];//非常重要,就是崩溃的原因
NSString *name = [exception name];//异常类型
NSString *crashLogInfo = [NSString stringWithFormat:@"exception type : %@ \n crash reason : %@ \n call stack info : %@", name, reason, arr];
DebugLog(@"APP Crash,%@",crashLogInfo);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableFilePath = [documentsDirectory stringByAppendingPathComponent:CRASHLOG_PATH];
char szFilePath[512] = {0};
[writableFilePath getCString:szFilePath maxLength:sizeof(szFilePath) encoding:NSASCIIStringEncoding];
FILE* hFile = NULL;
if((hFile = fopen(szFilePath, "a+"))!=NULL)
{
NSDate *now = [NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * strDate=[dateformatter stringFromDate:now];
fprintf(hFile, "\n");
fprintf(hFile, "%s : \n",[strDate UTF8String]);
fprintf(hFile, "%s",[crashLogInfo UTF8String]);
fclose(hFile);
}
}
然后在程序入口处调用这个方法即可
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
}
- 程序中引入crash日志文件
- android 处理程序crash日志
- 上传程序crash的日志------bugly
- C++程序中引入.a(静态库)文件
- 崩溃日志Crash文件分析方法
- iOS利用dSYM文件解析crash日志
- 程序的中写日志文件
- 使用MAP文件定位程序Crash
- 程序Crash调试方式--MAP文件
- android 程序崩溃自动生成Crash文件
- 在Java项目中引入日志
- 平时程序中遇到的crash(一)
- thinkphp中引入文件陷阱
- Spring中引入properties文件
- Spring中引入properties文件
- 事件中 引入 js文件
- spring中引入其他文件
- xcode 符号化崩溃日志.crash 或 .ips文件
- 应用写库异常问题分析
- copy协议解析
- ASP.NET 使用Ajax
- 5-37 整数分解为若干项之和 (20分)
- UVA1252 Twenty Questions dp & set
- 程序中引入crash日志文件
- 孙子兵法全文(附译文)
- [leetcode] 67. Add Binary
- iOS 调整一个label 上的字体间距与行间距
- js中Date()的用法及日期计算方法
- jvm 5块内存 堆,栈等
- 基于zookeeper-3.4.5-cdh5.7.1的kafka_2.9.2-0.8.1.1的安装
- DAY04_密文的层层解析
- Leetcode 299. Bulls and Cows