Need more test
This commit is contained in:
parent
c5842a7fbe
commit
767bfbd81d
@ -25,12 +25,17 @@ class BaseFormatter(Options):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def info(cls) -> str:
|
def info(cls) -> str:
|
||||||
cache = "## Base Formatter\n"
|
infos = {BaseFormatter.name: BaseFormatter._info()}
|
||||||
cache += BaseFormatter._info()
|
# cache = "## Base Formatter\n"
|
||||||
cache += f"## {cls.name}\n"
|
# cache += BaseFormatter._info()
|
||||||
cache += cls._info()
|
# cache += f"## {cls.name}\n"
|
||||||
|
# cache += cls._info()
|
||||||
|
cache = ''
|
||||||
for formatter in cls.sub_formatter:
|
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
|
return cache
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -149,9 +154,23 @@ class LevelFormatter(BaseFormatter):
|
|||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
class StdFormatter(BaseFormatter):
|
||||||
|
name = 'StdFormatter'
|
||||||
|
|
||||||
|
sub_formatter = [TimeFormatter(), LevelFormatter()]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _info(cls) -> str:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(TimeFormatter.info())
|
print(TimeFormatter.info())
|
||||||
print(TimeFormatter().format_message(LogMessage(messages=['Hello World!'])))
|
print(TimeFormatter().format_message(LogMessage(messages=['Hello World!'])))
|
||||||
|
|
||||||
print(LevelFormatter.info())
|
print(LevelFormatter.info())
|
||||||
print(LevelFormatter().format_message(LogMessage(messages=['Hello World!'], level=10)))
|
print(LevelFormatter().format_message(LogMessage(messages=['Hello World!'], level=10)))
|
||||||
|
|
||||||
|
print(StdFormatter.info())
|
||||||
|
print(StdFormatter().format_message(LogMessage(messages=['Hello World!'], level=10)))
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from lib_not_dr.logger.formatter import BaseFormatter, TimeFormatter, LevelFormatter
|
from lib_not_dr.logger.formatter import BaseFormatter, TimeFormatter, LevelFormatter
|
||||||
|
from lib_not_dr.logger.structers import LogMessage
|
||||||
|
|
||||||
|
|
||||||
class FormatterTest(unittest.TestCase):
|
class FormatterTest(unittest.TestCase):
|
||||||
@ -22,3 +23,7 @@ class FormatterTest(unittest.TestCase):
|
|||||||
def test_level_formatter(self):
|
def test_level_formatter(self):
|
||||||
formatter = LevelFormatter()
|
formatter = LevelFormatter()
|
||||||
formatter.info()
|
formatter.info()
|
||||||
|
|
||||||
|
def test_std_formatter(self):
|
||||||
|
formatter = BaseFormatter()
|
||||||
|
formatter.info()
|
||||||
|
Loading…
Reference in New Issue
Block a user