1
0
Fork 0
CrawlerEngines/utils/logger.py

43 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)