我是靠谱客的博主 知性树叶,这篇文章主要介绍android app log抓取汇总,现在分享给大家,希望可以做个参考。

logcat

apk 抓取logcat log到sdcard

复制代码
1
2
3
4
5
6
7
8
9
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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 文件获取

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(86)

评论列表共有 0 条评论

立即
投稿
返回
顶部