mini-rbac/backend/core/log.py

16 lines
413 B
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.

import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# 创建一个 FileHandler用于写入日志文件
handler = logging.FileHandler('log_file.log')
handler.setLevel(logging.INFO)
# 设置日志格式
formatter = logging.Formatter("[%(asctime)s] %(levelname)s %(message)s")
handler.setFormatter(formatter)
# 添加 FileHandler 到日志处理器中
logger.addHandler(handler)