34 lines
827 B
Python
34 lines
827 B
Python
|
import logging
|
||
|
from logging.handlers import RotatingFileHandler
|
||
|
|
||
|
|
||
|
# 配置日志
|
||
|
def setup_logger():
|
||
|
logger = logging.getLogger("launcher.log")
|
||
|
logger.setLevel(logging.DEBUG)
|
||
|
|
||
|
# 控制台输出
|
||
|
console_handler = logging.StreamHandler()
|
||
|
console_handler.setLevel(logging.DEBUG)
|
||
|
|
||
|
# 文件输出
|
||
|
file_handler = RotatingFileHandler(
|
||
|
"launcher.log", maxBytes=5 * 1024 * 1024, backupCount=3
|
||
|
)
|
||
|
file_handler.setLevel(logging.INFO)
|
||
|
|
||
|
# 设置格式化器
|
||
|
formatter = logging.Formatter("%(asctime)s [%(levelname)s] - %(message)s")
|
||
|
console_handler.setFormatter(formatter)
|
||
|
file_handler.setFormatter(formatter)
|
||
|
|
||
|
# 添加 Handler
|
||
|
logger.addHandler(console_handler)
|
||
|
logger.addHandler(file_handler)
|
||
|
|
||
|
return logger
|
||
|
|
||
|
|
||
|
# 创建全局 Logger 实例
|
||
|
logger = setup_logger()
|