mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-07-15 20:53:00 +08:00
add nonebot log filter
This commit is contained in:
parent
a7ccb977d3
commit
293d62c03a
@ -38,3 +38,5 @@
|
|||||||
## [0.4.3]
|
## [0.4.3]
|
||||||
- 使用playwright替换pypeteer(大概能修复渲染失败图片之后CPU跑满的问题)
|
- 使用playwright替换pypeteer(大概能修复渲染失败图片之后CPU跑满的问题)
|
||||||
- 增加了help插件`nonebot-plugin-help`
|
- 增加了help插件`nonebot-plugin-help`
|
||||||
|
- 修复playwright漏内存的问题
|
||||||
|
- 增加过滤nonebot日志功能
|
||||||
|
@ -12,6 +12,7 @@ class PlugConfig(BaseSettings):
|
|||||||
bison_init_filter: bool = True
|
bison_init_filter: bool = True
|
||||||
bison_use_queue: bool = True
|
bison_use_queue: bool = True
|
||||||
bison_outer_url: str = 'http://localhost:8080/bison/'
|
bison_outer_url: str = 'http://localhost:8080/bison/'
|
||||||
|
bison_filter_log: bool = False
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
extra = 'ignore'
|
extra = 'ignore'
|
||||||
|
@ -4,15 +4,17 @@ from html import escape
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from time import asctime
|
from time import asctime
|
||||||
from typing import Awaitable, Callable, Optional
|
from typing import Awaitable, Callable, Optional, Union
|
||||||
|
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
import nonebot
|
import nonebot
|
||||||
from nonebot.adapters.cqhttp.message import MessageSegment
|
from nonebot.adapters.cqhttp.message import MessageSegment
|
||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
|
from nonebot.log import default_format
|
||||||
from playwright._impl._driver import compute_driver_executable
|
from playwright._impl._driver import compute_driver_executable
|
||||||
from playwright.async_api import Browser, Page, async_playwright, Playwright
|
from playwright.async_api import Browser, Page, Playwright, async_playwright
|
||||||
|
|
||||||
from .plugin_config import plugin_config
|
from .plugin_config import plugin_config
|
||||||
|
|
||||||
@ -146,3 +148,30 @@ def html_to_text(html: str, query_dict: dict = {}) -> str:
|
|||||||
assert node is not None
|
assert node is not None
|
||||||
return node.text.strip()
|
return node.text.strip()
|
||||||
|
|
||||||
|
|
||||||
|
class Filter:
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.level: Union[int, str] = "DEBUG"
|
||||||
|
|
||||||
|
def __call__(self, record):
|
||||||
|
module_name: str = record["name"]
|
||||||
|
module = sys.modules.get(module_name)
|
||||||
|
if module:
|
||||||
|
module_name = getattr(module, "__module_name__", module_name)
|
||||||
|
record["name"] = module_name.split(".")[0]
|
||||||
|
levelno = logger.level(self.level).no if isinstance(self.level,
|
||||||
|
str) else self.level
|
||||||
|
nonebot_warning_level = logger.level("WARNING").no
|
||||||
|
return record["level"].no >= levelno if record["name"] != "nonebot" \
|
||||||
|
else record["level"].no >= nonebot_warning_level
|
||||||
|
|
||||||
|
if plugin_config.bison_filter_log:
|
||||||
|
logger.remove()
|
||||||
|
default_filter = Filter()
|
||||||
|
logger.add(sys.stdout,
|
||||||
|
colorize=True,
|
||||||
|
diagnose=False,
|
||||||
|
filter=default_filter,
|
||||||
|
format=default_format)
|
||||||
|
logger.success("Muted info & success from nonebot")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user