From 58999777aa04d1f8c005b1c779059d26952fe447 Mon Sep 17 00:00:00 2001 From: "wenzhouwww@live.cn" Date: Mon, 11 Jul 2022 14:28:51 +0800 Subject: [PATCH] update get_datetime method --- tests/pytest/crash_gen/shared/misc.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/pytest/crash_gen/shared/misc.py b/tests/pytest/crash_gen/shared/misc.py index b1259d325b..fd73f97fcb 100644 --- a/tests/pytest/crash_gen/shared/misc.py +++ b/tests/pytest/crash_gen/shared/misc.py @@ -44,6 +44,10 @@ class MyLoggingAdapter(logging.LoggerAdapter): class Logging: logger = None # type: Optional[MyLoggingAdapter] + @classmethod + def _get_datetime(cls): + return datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] + @classmethod def getLogger(cls): return cls.logger @@ -68,23 +72,19 @@ class Logging: @classmethod def info(cls, msg): - date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] - cls.logger.info("[time]: " + date +" [msg]: "+ msg) + cls.logger.info("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def debug(cls, msg): - date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] - cls.logger.debug("[time]: " + date +" [msg]: "+ msg) + cls.logger.debug("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def warning(cls, msg): - date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] - cls.logger.warning("[time]: " + date +" [msg]: "+ msg) + cls.logger.warning("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def error(cls, msg): - date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] - cls.logger.error("[time]: " + date +" [msg]: "+ msg) + cls.logger.error("[time]: " + cls._get_datetime() +" [msg]: "+ msg) class Status: STATUS_EMPTY = 99 -- GitLab