mirror of
https://github.com/LC044/WeChatMsg
synced 2024-11-15 06:11:19 +08:00
34 lines
1009 B
Python
34 lines
1009 B
Python
import logging
|
|
import os
|
|
import time
|
|
import traceback
|
|
from functools import wraps
|
|
|
|
filename = time.strftime("%Y-%m-%d", time.localtime(time.time()))
|
|
if not os.path.exists('./app/log/logs'):
|
|
os.mkdir('./app/log/logs')
|
|
logger = logging.getLogger('test')
|
|
logger.setLevel(level=logging.DEBUG)
|
|
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
|
|
file_handler = logging.FileHandler(f'./app/log/logs/{filename}-log.log')
|
|
file_handler.setLevel(level=logging.INFO)
|
|
file_handler.setFormatter(formatter)
|
|
|
|
stream_handler = logging.StreamHandler()
|
|
stream_handler.setLevel(logging.DEBUG)
|
|
stream_handler.setFormatter(formatter)
|
|
|
|
logger.addHandler(file_handler)
|
|
logger.addHandler(stream_handler)
|
|
|
|
|
|
def log(func):
|
|
@wraps(func)
|
|
def log_(*args, **kwargs):
|
|
try:
|
|
return func(*args, **kwargs)
|
|
except Exception as e:
|
|
logger.error(f"\n{func.__qualname__} is error,here are details:\n{traceback.format_exc()}")
|
|
|
|
return log_
|