feat(core): 引入 VERBOSE 级别日志

This commit is contained in:
XcantloadX 2025-02-14 17:31:53 +08:00
parent 95f4111647
commit 0077062263
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,2 @@
from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL, basicConfig
from .log import getLogger, enable_verbose, LEVEL_VERBOSE as VERBOSE

18
kotonebot/logging/log.py Normal file
View File

@ -0,0 +1,18 @@
import logging
from typing import cast
LEVEL_VERBOSE = 5
def enable_verbose():
logging.addLevelName(LEVEL_VERBOSE, 'VERBOSE')
class VerboseLogger(logging.Logger):
def verbose(self, msg, *args, **kwargs):
if self.isEnabledFor(LEVEL_VERBOSE):
self._log(LEVEL_VERBOSE, msg, args, **kwargs)
def getLogger(name: str | None = None) -> VerboseLogger:
logger = logging.getLogger(name)
if not isinstance(logger, VerboseLogger):
logger.__class__ = VerboseLogger
return cast(VerboseLogger, logger)