问题描述
我想知道如何从android设备上获取完整的日志(从我的应用程序初始化到崩溃或直到强制关闭我的应用程序为止).
I was wondering how do i take complete logs from android device (From the point of My application initialize to any crash or till force close of my application).
我在这里发布的原因是我的应用程序崩溃了,但是当我使用 DDMS/Logcat 记录日志时,崩溃详细信息被新日志覆盖.
Reason i am posting here is my application is crashed some point,but when i take logs using DDMS/Logcat my crash details are over written with new logs.
我如何获取崩溃的原因日志..
How do i get my crashed reason logs..
特别希望捕获本机代码崩溃.
Specially looking to capture Native Code Crash.
即 I/DEBUG(21835):信号11(SIGSEGV),代码1(SEGV_MAPERR),故障加法器00000004 ...
此 adb logcat> crash.txt 是否可以确保我永久写入文件?
Will this adb logcat > crash.txt ensures me that write to file will happen forever?
推荐答案
我试过了,效果很好,不确定会消耗多少电池.如果您的应用程序处于测试阶段,则可以使用它.必须删除此代码并发布..
I tried this Works Real Well,Not sure How much battery it will consume..If your Application is in Testing Stage You can use this..Before Release you got to Remove this code and Publish..
private void writeADBLogs(){
BufferedWriter bufferedWriter = null;
try {
final File file = new File(sdcardPath);
bufferedWriter = new BufferedWriter(new FileWriter(file,true));
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream()));
String oneLine;
while ((oneLine= bufferedReader.readLine()) != null) {
bufferedWriter.write(oneLine);
bufferedWriter.newLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
这篇关于在Android中捕获完整的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!