StarRailCopilot/module/logger.py
LmeSzinc 8ec5099b58 Add: 适配穹顶下的圣咏曲AC图
- 修复UI导致的动态边缘识别出错
- 修复只识别出一队时的处理逻辑
- 修复处理战斗结束后跳出的剧情
- 修复辅助点击报CampaignEnd
- 修复游戏出现白屏bug时, 连续点击使用紧急维修
- 增加地图全清时, 使用二队打BOSS, 忽略FLEET_BOSS
- 增加被精英抓住的识别, 暂时还用不到
2020-05-22 21:48:56 +08:00

55 lines
1.4 KiB
Python

import logging
import datetime
import os
import sys
from collections import deque
pyw_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
if f'{pyw_name}.pyw' not in os.listdir('./'):
pyw_name = 'default'
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d | %(levelname)s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
console = logging.StreamHandler()
console.setFormatter(formatter)
logger.addHandler(console)
log_file = f'./log/{datetime.date.today()}_{pyw_name}.txt'
try:
file = logging.FileHandler(log_file)
except FileNotFoundError:
os.mkdir('./log')
file = logging.FileHandler(log_file)
file.setFormatter(formatter)
logger.addHandler(file)
def hr(title, level=3):
title = str(title).upper()
if level == 1:
logger.info('=' * 20 + ' ' + title + ' ' + '=' * 20)
if level == 2:
logger.info('-' * 20 + ' ' + title + ' ' + '-' * 20)
if level == 3:
logger.info('<' * 3 + ' ' + title + ' ' + '>' * 3)
if level == 0:
middle = '|' + ' ' * 20 + title + ' ' * 20 + '|'
border = '+' + '-' * (len(middle) - 2) + '+'
logger.info(border)
logger.info(middle)
logger.info(border)
def attr(name, text):
logger.info('[%s] %s' % (str(name), str(text)))
logger.hr = hr
logger.attr = attr
logger.screenshot_deque = deque(maxlen=60)
logger.hr('Start', level=0)