import logging
import os
from datetime import datetime
import requests

if not os.path.exists("logs"):
    os.makedirs("logs")

# 配置日志的基本设置
logging.basicConfig(
    filename=os.path.join("logs", datetime.now().strftime("%Y-%m-%d") + ".log"),
    level=logging.WARNING,
    format="%(asctime)s:%(levelname)s:%(message)s",
    filemode="a",
    encoding="utf-8",
)

# 设置requests库的日志级别为WARNING或更高，以确保不记录INFO或DEBUG级别的日志
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("elasticsearch").setLevel(logging.WARNING)


class logger:
    # def debug(msg: str):
    #     logging.debug(msg)

    # def info(msg: str):
    # logging.info(msg)

    def warning(msg, printLog=True):
        logging.warning(msg)
        if printLog == True:
            print(msg)

    def error(msg: str, printLog=True):
        logging.error(msg)
        if printLog == True:
            print(msg)

    # def critical(msg: str):
    #     logging.critical(msg)
