diff --git a/nonebot/__init__.py b/nonebot/__init__.py index 74811e10..8d2a78f3 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -262,11 +262,7 @@ def init(*, _env_file: Optional[str] = None, **kwargs): _env_file=_env_file or f".env.{env.environment}", ) - default_filter.level = ( - ("DEBUG" if config.debug else "INFO") - if config.log_level is None - else config.log_level - ) + default_filter.level = config.log_level logger.opt(colors=True).info( f"Current Env: {escape_tag(env.environment)}" ) diff --git a/nonebot/config.py b/nonebot/config.py index 818f7c36..d8b4b5e4 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -189,19 +189,10 @@ class Config(BaseConfig): NoneBot 的 HTTP 和 WebSocket 服务端监听的端口。 """ - debug: bool = False - """ - - **类型**: ``bool`` - - **默认值**: ``False`` - - :说明: - - 是否以调试模式运行 NoneBot。 - """ - log_level: Optional[Union[int, str]] = None + log_level: Union[int, str] = "INFO" """ - **类型**: ``Union[int, str]`` - - **默认值**: ``None`` + - **默认值**: ``INFO`` :说明: diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index 57170a59..a9e93aca 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -63,15 +63,15 @@ class Config(BaseSettings): ``redoc`` 地址,默认为 ``None`` 即关闭 """ - fastapi_reload: Optional[bool] = None + fastapi_reload: bool = False """ :类型: - ``Optional[bool]`` + ``bool`` :说明: - 开启/关闭冷重载,默认会在配置了 app 的 debug 模式启用 + 开启/关闭冷重载 """ fastapi_reload_dirs: Optional[List[str]] = None """ @@ -127,7 +127,6 @@ class Driver(ReverseDriver): self.fastapi_config: Config = Config(**config.dict()) self._server_app = FastAPI( - debug=config.debug, openapi_url=self.fastapi_config.fastapi_openapi_url, docs_url=self.fastapi_config.fastapi_docs_url, redoc_url=self.fastapi_config.fastapi_redoc_url, @@ -221,14 +220,11 @@ class Driver(ReverseDriver): app or self.server_app, # type: ignore host=host or str(self.config.host), port=port or self.config.port, - reload=self.fastapi_config.fastapi_reload - if self.fastapi_config.fastapi_reload is not None - else (bool(app) and self.config.debug), + reload=self.fastapi_config.fastapi_reload, reload_dirs=self.fastapi_config.fastapi_reload_dirs, reload_delay=self.fastapi_config.fastapi_reload_delay, reload_includes=self.fastapi_config.fastapi_reload_includes, reload_excludes=self.fastapi_config.fastapi_reload_excludes, - debug=self.config.debug, log_config=LOGGING_CONFIG, **kwargs, ) diff --git a/nonebot/drivers/quart.py b/nonebot/drivers/quart.py index fbd66a25..1f5df4c6 100644 --- a/nonebot/drivers/quart.py +++ b/nonebot/drivers/quart.py @@ -40,15 +40,15 @@ class Config(BaseSettings): Quart 驱动框架设置 """ - quart_reload: Optional[bool] = None + quart_reload: bool = False """ :类型: - ``Optional[bool]`` + ``bool`` :说明: - 开启/关闭冷重载,默认会在配置了 app 的 debug 模式启用 + 开启/关闭冷重载 """ quart_reload_dirs: Optional[List[str]] = None """ @@ -199,14 +199,11 @@ class Driver(ReverseDriver): app or self.server_app, # type: ignore host=host or str(self.config.host), port=port or self.config.port, - reload=self.quart_config.quart_reload - if self.quart_config.quart_reload is not None - else (bool(app) and self.config.debug), + reload=self.quart_config.quart_reload, reload_dirs=self.quart_config.quart_reload_dirs, reload_delay=self.quart_config.quart_reload_delay, reload_includes=self.quart_config.quart_reload_includes, reload_excludes=self.quart_config.quart_reload_excludes, - debug=self.config.debug, log_config=LOGGING_CONFIG, **kwargs, ) diff --git a/nonebot/log.py b/nonebot/log.py index 1caa4789..b3c520cd 100644 --- a/nonebot/log.py +++ b/nonebot/log.py @@ -31,7 +31,7 @@ logger: "Logger" = loguru.logger :默认信息: * 格式: ``[%(asctime)s %(name)s] %(levelname)s: %(message)s`` - * 等级: ``DEBUG`` / ``INFO`` ,根据 config 配置改变 + * 等级: ``INFO`` ,根据 ``config,log_level`` 配置改变 * 输出: 输出至 stdout :用法: @@ -49,7 +49,7 @@ logger: "Logger" = loguru.logger class Filter: def __init__(self) -> None: - self.level: Union[int, str] = "DEBUG" + self.level: Union[int, str] = "INFO" def __call__(self, record): module_name: str = record["name"] diff --git a/nonebot/plugin/on.py b/nonebot/plugin/on.py index 0520488a..e9b56395 100644 --- a/nonebot/plugin/on.py +++ b/nonebot/plugin/on.py @@ -4,8 +4,6 @@ import inspect from types import ModuleType from typing import Any, Set, Dict, List, Type, Tuple, Union, Optional -from nonebot.params import State -from nonebot.adapters import Event from nonebot.matcher import Matcher from .manager import _current_plugin from nonebot.permission import Permission diff --git a/nonebot/utils.py b/nonebot/utils.py index 50044074..b8bc4af5 100644 --- a/nonebot/utils.py +++ b/nonebot/utils.py @@ -155,7 +155,7 @@ def logger_wrapper(logger_name: str): :log 参数: - * ``level: Literal['WARNING', 'DEBUG', 'INFO']``: 日志等级 + * ``level: Literal["CRETICAL", "WARNING", "INFO", "DEBUG", "TRACE"]``: 日志等级 * ``message: str``: 日志信息 * ``exception: Optional[Exception]``: 异常信息 """ diff --git a/website/docs/tutorial/choose-driver.md b/website/docs/tutorial/choose-driver.md index 898d9f24..fea1dabb 100644 --- a/website/docs/tutorial/choose-driver.md +++ b/website/docs/tutorial/choose-driver.md @@ -62,6 +62,8 @@ FastAPI: [文档](https://fastapi.tiangolo.com/), [仓库](https://github.com/ti DRIVER=~fastapi ``` + + ### Quart 类型: `ReverseDriver` diff --git a/website/docs/tutorial/configuration.md b/website/docs/tutorial/configuration.md index 94ee90cd..d6af925c 100644 --- a/website/docs/tutorial/configuration.md +++ b/website/docs/tutorial/configuration.md @@ -65,7 +65,6 @@ NoneBot 默认会从 `.env.{ENVIRONMENT}` 文件加载配置,但是可以在 N ```bash HOST=0.0.0.0 # 配置 NoneBot 监听的 IP/主机名 PORT=8080 # 配置 NoneBot 监听的端口 -DEBUG=true # 开启 debug 模式 **请勿在生产环境开启** SUPERUSERS=["123456789", "987654321"] # 配置 NoneBot 超级用户 NICKNAME=["awesome", "bot"] # 配置机器人的昵称 COMMAND_START=["/", ""] # 配置命令起始字符