lib-not-dr/example/logger/formatter.py

49 lines
1.3 KiB
Python
Raw Normal View History

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