概述
logcat
apk 抓取logcat log到sdcard
String cmd = "logcat -v threadtime -b all -f "+" /sdcard/log.txt";
Runtime runtime = Runtime.getRuntime();
try {
mLogcatProcess = runtime.exec(cmd);
} catch (Exception e) {
e.printStackTrace();
}
获取anr
通过读取/data/anr 数据,写入sdcard
private void doAnr() {
String file = mCrashFolderStr + "/" + "anr";
Log.d(TAG, "anr file = " + file);
File anr_folder = new File(file);
if (!anr_folder.exists()) anr_folder.mkdirs();
if (LoggerUtil.IS_EMULATOR) {
return;
}
File anr_file = new File("/data/anr");
File[] listFies = null;
if (anr_file.exists()) {
Log.d(TAG, "anr file exist,and files count is " + anr_file.list().length);
listFies = anr_file.listFiles();
}
for (int i = 0; i < listFies.length; i++) {
String cmd = "cat
/data/anr/" + listFies[i].getName();
BufferedReader bufferedReader = null;
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(cmd);
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
File out_file = new File(mCrashFolderStr + "/anr/" + listFies[i].getName());
if (!out_file.exists()) out_file.createNewFile();
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(out_file));
while ((line = bufferedReader.readLine()) != null) {
writer.write(line + "n");
}
writer.flush();
writer.close();
bufferedReader.close();
process.destroy();
process = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader = null;
}
}
}
}
tombstones 文件获取
private void doTombstone() {
String file = mCrashFolderStr + "/" + "tombstones";
Log.d(TAG, "tombstones file = " + file);
File tombstones_folder = new File(file);
if (!tombstones_folder.exists()) tombstones_folder.mkdirs();
if (LoggerUtil.IS_EMULATOR) {
return;
}
File tombstones_file = new File("/data/tombstones");
File[] listFies = null;
if (tombstones_file.exists()) {
listFies = tombstones_file.listFiles();
Log.d(TAG, "anr file exist,and files count is " + listFies.length);
//avc: denied { read } for name="tombstones" dev="dm-5" ino=88 scontext=u:r:system_app:s0 tcontext=u:object_r:tombstone_data_file:s0 tclass=dir permissive=0
}
for (int i = 0; i < listFies.length; i++) {
String cmd = "cat
/data/tombstones/" + listFies[i].getName();
BufferedReader bufferedReader = null;
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(cmd);
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
File out_file = new File(mCrashFolderStr + "/tombstones/" + listFies[i].getName());
if (!out_file.exists()) out_file.createNewFile();
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(out_file));
while ((line = bufferedReader.readLine()) != null) {
writer.write(line + "n");
}
writer.flush();
writer.close();
bufferedReader.close();
process.destroy();
process = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader = null;
}
}
}
}
最后
以上就是知性树叶为你收集整理的android app log抓取汇总的全部内容,希望文章能够帮你解决android app log抓取汇总所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复