lib-not-dr/example/logger/formatter.py
2023-12-03 16:36:01 +08:00

49 lines
1.3 KiB
Python

# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import inspect
from lib_not_dr.logger.structure import LogMessage
from lib_not_dr.logger.formatter import StdFormatter
if __name__ == "__main__":
levels = (0, 5, 7, 10, 20, 30, 40, 50)
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, 5, 7, 10, 20, 30, 40, 50)
print("with color")
for test_level in test_levels:
log_message.level = test_level
print(std_format.format_message(log_message), end="")
print(std_format.as_markdown())
print("without color")
std_format.enable_color = False
for test_level in test_levels:
log_message.level = test_level
print(std_format.format_message(log_message), end="")
print(std_format.as_markdown())