# -*- coding: utf-8 -*- """票 04:从服务日志提取 C1 50001 的堆栈。""" import io, sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') txt = open(r'e:\code\crm-backend-matt\logs\t04-run.log', encoding='utf-8', errors='replace').read() # 找最近的 ERROR/Exception 段 idx = txt.rfind('ERROR') if idx < 0: idx = txt.rfind('Exception') print('log size=', len(txt)) print(txt[max(0, idx - 500):idx + 2500] if idx >= 0 else '(no ERROR found)')