Repository navigation
Expand file tree
/
Copy pathBaseLogcat.py
More file actions
76 lines (71 loc) · 2.67 KB
/
Copy pathBaseLogcat.py
File metadata and controls
76 lines (71 loc) · 2.67 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
import os
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
class getCrashText:
def Count_crash(self, path):
# 分析logcat日志
count = 0
count_line = 0
word_list = ['ANR', 'FATAL']
with open(path + '/logcat.log', 'rt', encoding="ISO-8859-1") as f:
for line in f:
count_line += 1
for word in word_list:
if word in line:
text = f.readlines(count_line)
with open(path + "/crashInfo.txt", "a") as w:
w.write('=========================crash=========================\n')
w.writelines(text)
count += 1
w.close()
f.close()
return count
if __name__ == '__main__':
pass
path = PATH("../Log/CrashInfo/Android/")
count = getCrashText().Count_crash(path)
print(count)
# import os
# import re
#
# if __name__ == '__main__':
# monkey_log_list = [log for log in os.listdir('./monkeylogs') if log.endswith('.log')]
# devices_log_list = [log for log in os.listdir('./devicelogs') if log.endswith('.log')]
# word_list = ['ANR', 'FATAL']
# bug_count = 0
# line_count = 0
# flag = 0
#
# for log in devices_log_list:
# with open('./devicelogs/' + log, 'rt', encoding="ISO-8859-1") as f:
# for line in f:
# line_count += 1
# temp = re.match(r'\w.(.\d*).', line)
# if flag > 0:
# if temp is None:
# flag -= 1
# elif pid != temp.group(1):
# flag -= 1
# else:
# flag = 5
# with open("crashInfo.txt", "a") as w:
# w.write(line)
# w.close()
# continue
# for word in word_list:
# if word in line:
# pid = re.match(r'\w.(.\d*).', line).group(1)
# with open("crashInfo.txt", "a") as w:
# w.write('\n=========================crash for {0} {1} {2}=========================\n'
# .format(log, line_count, word))
# w.write(line)
# flag = 5
# bug_count += 1
# w.close()
# line_count = 0
#
# with open("\n\ncrashInfo.txt\n\n", "a") as w:
# w.write('Total bugs: {0}'.format(bug_count))
# w.close()