From 767bfbd81d74aa275fc66211a7f5a52119e44fb6 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 25 Oct 2023 06:20:26 +0800 Subject: [PATCH] Need more test --- lib_not_dr/logger/formatter.py | 29 ++++++++++++++++++++++++----- test/logger/formatter.py | 5 +++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib_not_dr/logger/formatter.py b/lib_not_dr/logger/formatter.py index 34c9dc4..58c365c 100644 --- a/lib_not_dr/logger/formatter.py +++ b/lib_not_dr/logger/formatter.py @@ -25,12 +25,17 @@ class BaseFormatter(Options): @classmethod def info(cls) -> str: - cache = "## Base Formatter\n" - cache += BaseFormatter._info() - cache += f"## {cls.name}\n" - cache += cls._info() + infos = {BaseFormatter.name: BaseFormatter._info()} + # cache = "## Base Formatter\n" + # cache += BaseFormatter._info() + # cache += f"## {cls.name}\n" + # cache += cls._info() + cache = '' for formatter in cls.sub_formatter: - cache += formatter.info() + infos[formatter.name] = formatter._info() + for name, info in infos.items(): + cache += f"## {name}\n" + cache += info return cache @classmethod @@ -149,9 +154,23 @@ class LevelFormatter(BaseFormatter): return message +class StdFormatter(BaseFormatter): + name = 'StdFormatter' + + sub_formatter = [TimeFormatter(), LevelFormatter()] + + @classmethod + def _info(cls) -> str: + return '' + + + if __name__ == '__main__': print(TimeFormatter.info()) print(TimeFormatter().format_message(LogMessage(messages=['Hello World!']))) print(LevelFormatter.info()) print(LevelFormatter().format_message(LogMessage(messages=['Hello World!'], level=10))) + + print(StdFormatter.info()) + print(StdFormatter().format_message(LogMessage(messages=['Hello World!'], level=10))) diff --git a/test/logger/formatter.py b/test/logger/formatter.py index fe10ed9..eae65ed 100644 --- a/test/logger/formatter.py +++ b/test/logger/formatter.py @@ -7,6 +7,7 @@ import unittest from lib_not_dr.logger.formatter import BaseFormatter, TimeFormatter, LevelFormatter +from lib_not_dr.logger.structers import LogMessage class FormatterTest(unittest.TestCase): @@ -22,3 +23,7 @@ class FormatterTest(unittest.TestCase): def test_level_formatter(self): formatter = LevelFormatter() formatter.info() + + def test_std_formatter(self): + formatter = BaseFormatter() + formatter.info()