"""
Dramatiq Worker Starter Logger
===============================

日志工具模块
"""

import logging
import sys


def setup_logging(
    level: int = logging.INFO,
    format_string: str | None = None,
    date_format: str | None = None,
) -> None:
    """
    配置日志

    :param level: 日志级别
    :type level: int
    :param format_string: 日志格式字符串
    :type format_string: str | None
    :param date_format: 日期格式字符串
    :type date_format: str | None
    """
    if format_string is None:
        format_string = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"

    if date_format is None:
        date_format = "%Y-%m-%d %H:%M:%S"

    logging.basicConfig(
        level=level,
        format=format_string,
        datefmt=date_format,
        stream=sys.stdout,
    )


def get_logger(name: str) -> logging.Logger:
    """
    获取日志记录器

    :param name: 日志记录器名称
    :type name: str
    :return: logging.Logger 实例
    :rtype: logging.Logger
    """
    return logging.getLogger(name)
