This commit is contained in:
shenjack 2023-10-24 00:02:11 +08:00
parent 20e81a00e8
commit 38b7e4f176
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -7,7 +7,7 @@
import time
from string import Template
from typing import List, Tuple, Dict, Union, Optional
from typing import List, Union, Optional
from lib_not_dr.types.options import Options
from structers import LogMessage, FormattingMessage
@ -25,7 +25,9 @@ class BaseFormatter(Options):
@classmethod
def info(cls) -> str:
cache = f"## {cls.name}\n"
cache = "## Base Formatter\n"
cache += BaseFormatter._info()
cache += f"## {cls.name}\n"
cache += cls._info()
for formatter in cls.sub_formatter:
cache += formatter.info()
@ -33,7 +35,11 @@ class BaseFormatter(Options):
@classmethod
def _info(cls) -> str:
return ''
info = cls.add_info('logger_name', 'logger name', 'The name of the logger')
info += '\n'
info += cls.add_info('logger_tag', 'logger tag', 'The tag of the logger')
info += '\n'
return info
def format_message(self,
message: LogMessage,
@ -88,6 +94,14 @@ class TimeFormatter(BaseFormatter):
return message
class LevelFormatter(BaseFormatter):
name = 'LevelFormatter'
@classmethod
def _info(cls) -> str:
return cls.add_info('level', 'log level', 'The log level')
if __name__ == '__main__':
print(TimeFormatter.info())
print(TimeFormatter().format_message(LogMessage(messages=['Hello World!'])))