add config for disable network warning log

This commit is contained in:
felinae98 2023-03-26 20:32:02 +08:00
parent 560fd81db6
commit 2796ea6f8e
3 changed files with 9 additions and 5 deletions

View File

@ -148,6 +148,7 @@ sidebar: auto
- `BISON_PROXY`: 使用的代理连接,形如`http://<ip>:<port>`(可选) - `BISON_PROXY`: 使用的代理连接,形如`http://<ip>:<port>`(可选)
- `BISON_UA`: 使用的 User-Agent默认为 Chrome - `BISON_UA`: 使用的 User-Agent默认为 Chrome
- `BISON_SHOW_NETWORK_WARNING`: 是否在日志中输出网络异常,默认开启
## 使用 ## 使用

View File

@ -93,6 +93,7 @@ class Platform(metaclass=PlatformABCMeta, base=True):
try: try:
return await self.fetch_new_post(target, users) return await self.fetch_new_post(target, users)
except httpx.RequestError as err: except httpx.RequestError as err:
if plugin_config.bison_show_network_warning:
logger.warning( logger.warning(
"network connection error: {}, url: {}".format( "network connection error: {}, url: {}".format(
type(err), err.request.url type(err), err.request.url
@ -100,6 +101,7 @@ class Platform(metaclass=PlatformABCMeta, base=True):
) )
return [] return []
except ssl.SSLError as err: except ssl.SSLError as err:
if plugin_config.bison_show_network_warning:
logger.warning(f"ssl error: {err}") logger.warning(f"ssl error: {err}")
return [] return []
except json.JSONDecodeError as err: except json.JSONDecodeError as err:

View File

@ -19,6 +19,7 @@ class PlugConfig(BaseSettings):
bison_resend_times: int = 0 bison_resend_times: int = 0
bison_proxy: Optional[str] bison_proxy: Optional[str]
bison_ua: str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" bison_ua: str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
bison_show_network_warning: bool = True
class Config: class Config:
extra = "ignore" extra = "ignore"