原文地址:https://cloud.tencent.com/developer/article/1502366
主要处理sdk版本9.9之后,日志加密方式改变了,生成的文件是后缀.cLog
的文件,以下脚本为提工单获取,仅保证当前可用。
留档日期:2022/8/22
工具说明:
1、在你电脑系统要有 python 2.x 环境
2、在终端运行 python decode_mars_log_file.py
就行了(log
文件要和 decode_mars_log_file.py
放在同一目录下)
复制以下代码保存到文件重命名为decode_mars_log_file.py
#!/usr/bin/python
import sys
import os
import glob
import zlib
import optparse
import struct
import binascii
import traceback
IO_BUFFER_SIZE = 4096
# This variable defines how deep you want the tool to
# scan subfolders to find clog files
recursive_level = 5
lastseq = 0
def DecompressFile(file, outfile):
dec = zlib.decompressobj(-zlib.MAX_WBITS)
fin = open(file, "rb")
fout = open(outfile, "wb")
buffer = fin.read(IO_BUFFER_SIZE)
while buffer:
decompressed = dec.decompress(buffer)
buffer = fin.read(IO_BUFFER_SIZE)
fout.write(decompressed)
decompressed = dec.flush()
fout.write(decompressed)
fout.close()
fin.close()
print(outfile)
def processfolder(folder, recursive_level):
if(recursive_level<=0):
return
filelist = glob.glob(folder "/*.clog")
for file in filelist:
DecompressFile(file, os.path.splitext(file)[0] '.log')
subfolders = glob.glob(folder "/*/")
for folder in subfolders:
processfolder(folder, recursive_level-1)
def process(arg):
if(arg.endswith('.clog') and os.path.isfile(arg)):
DecompressFile(arg, os.path.splitext(arg)[0] '.log')
elif(os.path.isdir(arg)):
processfolder(arg, recursive_level)
# decompress_clog.py now accept folder or file as arugments
# scenario 1 several files: python decompress_clog.py 1.clog 2.clog
# scenario 2 current folder: python decompress_clog.py ./
# scenario 3 several subfolders: python decompress_clog.py clogs 202101
def main():
global lastseq
args = sys.argv[1:]
if len(args) >= 1:
for arg in args:
process(arg)
else:
filelist = glob.glob("*.clog")
for filepath in filelist:
lastseq = 0
process(filepath)
if __name__ == "__main__":
main()