UAV_odm_merge/utils/logger.py
2024-12-30 17:34:21 +08:00

35 lines
1017 B
Python

import logging
import os
from datetime import datetime
def setup_logger(output_dir):
# 创建logs目录
log_dir = os.path.join(output_dir, 'logs')
# 创建日志文件名(包含时间戳)
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
log_file = os.path.join(log_dir, f'preprocess_{timestamp}.log')
# 配置日志格式
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# 配置文件处理器
file_handler = logging.FileHandler(log_file, encoding='utf-8')
file_handler.setFormatter(formatter)
# 配置控制台处理器
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
# 获取根日志记录器
logger = logging.getLogger('UAV_Preprocess')
logger.setLevel(logging.INFO)
# 添加处理器
logger.addHandler(file_handler)
logger.addHandler(console_handler)
return logger