# -*- coding: utf-8 -*- """票 04:testopp 日志关键行提取。""" import io, sys, re sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') txt = open(r'e:/code/crm-backend-matt/.scratch/opportunity-bugfix/t04-testopp.log', encoding='utf-8', errors='replace').read() for line in txt.splitlines(): if re.search(r'(STEP|EXIT=|BUILD |Tests run: \d+, Fail|Reactor Summary|crm-\w+ \.+|FAILURE|ERROR\])', line): print(line) print('--- tail 400 chars ---') print(txt[-400:])