Skip to content

Commit a43a17c

Browse files
committed
2.19.03.25 日志分析工具不在依赖任何字符集
1 parent 8e54557 commit a43a17c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

bin/mtlslog

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#-*- coding: UTF-8 -*-
33

44
import re
5+
import sys
56
import argparse
67
from collections import Counter
78

@@ -14,25 +15,26 @@ def log_slice(args,slow_log_handler):
1415
_endtime = args.endtime.encode(_charset)
1516
#迭代整个文件查找目标区间中的内容
1617
try:
18+
output_file = open(args.output_file,'bw')
1719
for line in slow_log_handler:
1820
#如果_find被标记为True,说明当前line正位于目标区间
1921
if _finde == True:
2022
#说明当前line位于目标区间,直接打印当前line,并判断是否已经到了退出的位置
2123
# 有可能遇到 latin1 都解码不了的情况
22-
print(line.decode(_charset),end='')
24+
output_file.write(line)
2325
if _endtime in line:
2426
break
2527
continue
2628
#判断是否已经进行目标区间
2729
if _finde == False:
2830
if _starttime in line:
2931
_finde=True
30-
print(line.decode(_charset),end='')
32+
output_file.write(line)
3133
except Exception as err:
32-
if _charset == 'latin1':
33-
pass
34-
else:
35-
raise err
34+
print(err)
35+
sys.exit()
36+
finally:
37+
output_file.close()
3638

3739

3840
def hot_table(args,slow_log_handler):
@@ -105,6 +107,7 @@ operations = {
105107
if __name__=="__main__":
106108
parser=argparse.ArgumentParser()
107109
parser.add_argument('--slow-log-file',help='slow log file absolute path')
110+
parser.add_argument('--output-file',default='/tmp/s.log',help='output file')
108111
parser.add_argument('--starttime',help='slow log start time flag')
109112
parser.add_argument('--endtime',help='slow log end time flag')
110113
parser.add_argument('--charset',default='latin1')
39 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)