init commit
This commit is contained in:
21
logging_setup.py
Normal file
21
logging_setup.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
简单的日志初始化模块
|
||||
使用:
|
||||
from logging_setup import init_logging
|
||||
init_logging()
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
def init_logging(level: str = None):
|
||||
lvl = (level or os.getenv("LOG_LEVEL", "INFO")).upper()
|
||||
lvl_value = getattr(logging, lvl, logging.INFO)
|
||||
logging.basicConfig(
|
||||
level=lvl_value,
|
||||
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
# 降低第三方库的默认日志噪音
|
||||
logging.getLogger("urllib3").setLevel(max(logging.WARNING, lvl_value))
|
||||
logging.getLogger("requests").setLevel(max(logging.WARNING, lvl_value))
|
||||
Reference in New Issue
Block a user