Files
fcb_photo_review/config/log.py
2024-05-17 16:16:56 +08:00

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 配置字典
LOGGING_CONFIG = {
'version': 1, # 必需,指定配置格式的版本
'disable_existing_loggers': False, # 是否禁用已经存在的logger实例
# formatters定义了不同格式的日志样式
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
# handlers定义了不同类型的日志处理器
'handlers': {
'console': {
'class': 'logging.StreamHandler', # 控制台处理器
'level': 'DEBUG',
'formatter': 'standard',
'stream': 'ext://sys.stdout', # 输出到标准输出默认编码跟随系统一般为UTF-8
},
'file': {
'class': 'logging.handlers.RotatingFileHandler', # 文件处理器,支持日志滚动
'level': 'INFO',
'formatter': 'standard',
'filename': 'log/fcb_photo_review.log', # 日志文件路径
'maxBytes': 1024 * 1024 * 5, # 文件最大大小这里为5MB
'backupCount': 5, # 保留的备份文件数量
'encoding': 'utf-8', # 显式指定文件编码为UTF-8以支持中文
},
},
# loggers定义了日志记录器这里是根记录器
'loggers': {
'': { # 根记录器
'handlers': ['console', 'file'], # 关联的处理器
'level': 'DEBUG', # 根记录器的级别
'propagate': False, # 是否向上级传播日志信息
},
},
}