add example for formatter ( since logger is not done, then add formatter first

This commit is contained in:
shenjack 2023-11-02 22:41:12 +08:00
parent 61d041de7e
commit 24502447a4
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 38 additions and 3 deletions

View File

@ -0,0 +1,35 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import inspect
from lib_not_dr.logger.structers import LogMessage
from lib_not_dr.logger.formatter import (StdFormatter,
TimeFormatter,
LevelFormatter,
TraceFormatter)
if __name__ == '__main__':
levels = (0, 2, 5, 7, 10, 30, 50, 90)
log_message = LogMessage(messages=['Hello World!'],
level=7,
stack_trace=inspect.currentframe(),
logger_tag='tester',
logger_name='test')
print(StdFormatter.info())
print(StdFormatter().format_message(log_message))
std_format = StdFormatter()
std_format.default_template = "${log_time}|${logger_name}|${logger_tag}|${log_source}:${log_line}|${log_function}|${level}|${messages}"
test_levels = (0, 2, 5, 7, 10, 30, 50, 90)
for test_level in test_levels:
log_message.level = test_level
print(std_format.format_message(log_message), end='')

View File

@ -166,11 +166,11 @@ class TraceFormatter(BaseFormatter):
@classmethod
def _info(cls) -> str:
info = cls.add_info('logging file', 'log_source', 'the logging file name')
info = cls.add_info('log_source', 'logging file', 'the logging file name')
info += '\n'
info += cls.add_info('logging line', 'log_line', 'the logging line number')
info += cls.add_info('log_line', 'logging line', 'the logging line number')
info += '\n'
info += cls.add_info('logging function', 'log_function', 'the logging function name')
info += cls.add_info('log_function', 'logging function', 'the logging function name')
return info
def _format(self, message: FormattingMessage) -> FormattingMessage: