Skip to content

Commit ad692a1

Browse files
committed
refactor: optimize jm_log compatibility with arity detection and warnings
1 parent f4a64b8 commit ad692a1

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/jmcomic/jm_config.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,23 @@ def get_fix_ts_token_tokenparam(cls):
407407
@classmethod
408408
def jm_log(cls, topic: str, msg: str, e: Exception = None):
409409
if cls.FLAG_ENABLE_JM_LOG is True:
410-
try:
411-
cls.EXECUTOR_LOG(topic, msg, e)
412-
except TypeError:
413-
cls.EXECUTOR_LOG(topic, msg)
410+
executor = cls.EXECUTOR_LOG
411+
if e is None:
412+
executor(topic, msg)
413+
else:
414+
import inspect
415+
try:
416+
sig = inspect.signature(executor)
417+
params_count = len(sig.parameters)
418+
except (ValueError, TypeError):
419+
params_count = 2
420+
421+
if params_count >= 3:
422+
executor(topic, msg, e)
423+
else:
424+
import warnings
425+
warnings.warn('jmcomic已升级到标准logging,建议将EXECUTOR_LOG重新定义为3个参数以接收异常对象 (topic, msg, e)')
426+
executor(topic, msg)
414427

415428
@classmethod
416429
def disable_jm_log(cls):

0 commit comments

Comments
 (0)