Files
RPA-ROBOT/utils/__init__.py
2026-08-26 16:14:47 +08:00

30 lines
908 B
Python
Raw Permalink 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
from datetime import datetime
def get_logger(name: str) -> logging.Logger:
"""创建仅输出到控制台的 logger"""
logger = logging.getLogger(name)
if not logger.handlers:
logger.setLevel(logging.INFO)
fmt = logging.Formatter("[%(asctime)s] %(name)s %(levelname)s - %(message)s")
sh = logging.StreamHandler()
sh.setFormatter(fmt)
logger.addHandler(sh)
return logger
def now_str(fmt: str = "%Y%m%d%H%M") -> str:
"""返回当前时间字符串,用于文件命名"""
return datetime.now().strftime(fmt)
# 注意:该导入必须放在 get_logger/now_str 定义之后——
# notify 模块内部通过 from . import get_logger 引用本包,
# 若放在定义之前会形成循环导入utils → notify → utils
from .notify import show_warning_countdown