-
Notifications
You must be signed in to change notification settings - Fork 99
/
log.py
27 lines (22 loc) · 796 Bytes
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import logging
import os
import sys
import time
filename = time.strftime("%Y-%m-%d", time.localtime(time.time()))
try:
if not os.path.exists('log'):
os.mkdir('log')
log_file = f'log/{filename}-log.log'
console_file = f'log/{filename}-output.log'
except:
log_file = f'{filename}-log.log'
console_file = f'{filename}-output.log'
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# pyinstaller 输出日志到文件
f = open(console_file, 'a')
sys.stdout = f
sys.stderr = f
file_handler = logging.FileHandler(log_file, encoding='utf-8')
logging.basicConfig(level='DEBUG', format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
logging.getLogger().addHandler(file_handler)
LOG = logging.getLogger("WechatMoments")