From 32dcb5bd6bc74ac0fc9270a2e55f03d93bf30025 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 15 Jun 2023 13:08:50 +0800 Subject: [PATCH] :lock: Filter bot_token in log --- utils/log/_traceback.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/log/_traceback.py b/utils/log/_traceback.py index 9918a22..7ef9c34 100644 --- a/utils/log/_traceback.py +++ b/utils/log/_traceback.py @@ -22,6 +22,7 @@ from rich.traceback import ( Traceback as BaseTraceback, ) +from core.config import config from utils.log._style import MonokaiProStyle if TYPE_CHECKING: @@ -199,7 +200,7 @@ class Traceback(BaseTraceback): name=frame_summary.f_code.co_name, locals={ key: pretty.traverse( - value, + Traceback.filter_value(value), max_length=locals_max_length, max_string=locals_max_string, max_depth=locals_max_depth, @@ -343,3 +344,9 @@ class Traceback(BaseTraceback): if frame.locals else syntax ) + + @staticmethod + def filter_value(value: Any) -> Any: + if isinstance(value, str): + return value.replace(config.bot_token, "TOKEN") + return value