2023-11-02 22:41:12 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
|
2023-11-05 13:32:31 +08:00
|
|
|
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-11-02 22:41:12 +08:00
|
|
|
|
|
|
|
|
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-11-02 22:41:12 +08:00
|
|
|
|
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",
|
|
|
|
)
|
2023-11-02 22:41:12 +08:00
|
|
|
|
|
|
|
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)
|
2023-11-02 23:48:36 +08:00
|
|
|
|
|
|
|
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="")
|
2023-11-02 23:48:36 +08:00
|
|
|
|
|
|
|
print(std_format.as_markdown())
|
|
|
|
|
|
|
|
print("without color")
|
|
|
|
|
|
|
|
std_format.enable_color = False
|
|
|
|
|
2023-11-02 22:41:12 +08:00
|
|
|
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="")
|
2023-11-02 23:48:36 +08:00
|
|
|
|
|
|
|
print(std_format.as_markdown())
|