2023-11-05 19:54:34 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
|
|
|
|
import time
|
|
|
|
import inspect
|
|
|
|
|
|
|
|
from lib_not_dr.logger.structure import LogMessage
|
|
|
|
from lib_not_dr.logger.outstream import FileCacheOutputStream, StdioOutputStream
|
|
|
|
|
2023-12-03 16:36:01 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
log_message = LogMessage(
|
|
|
|
messages=["Hello World!"],
|
|
|
|
level=20,
|
|
|
|
stack_trace=inspect.currentframe(),
|
|
|
|
logger_tag="tester",
|
|
|
|
logger_name="test",
|
|
|
|
)
|
|
|
|
|
|
|
|
file_cache = FileCacheOutputStream(file_name="test.log")
|
2023-11-05 19:54:34 +08:00
|
|
|
stdio = StdioOutputStream()
|
|
|
|
|
|
|
|
print(file_cache.as_markdown())
|
|
|
|
print(stdio.as_markdown())
|
|
|
|
|
|
|
|
file_cache.write_stdout(log_message)
|
|
|
|
stdio.write_stdout(log_message)
|
|
|
|
# wait for 10 sec
|
2023-12-03 16:36:01 +08:00
|
|
|
print("wait for 10 sec")
|
2023-11-06 00:19:39 +08:00
|
|
|
time.sleep(10)
|
2023-12-03 16:36:01 +08:00
|
|
|
print("look at the ./logs/test.log (sleep 5 sec)")
|
2023-11-06 00:19:39 +08:00
|
|
|
time.sleep(5)
|
2023-12-03 16:36:01 +08:00
|
|
|
print("go on")
|
2023-11-05 19:54:34 +08:00
|
|
|
# write 10 lines
|
|
|
|
|
|
|
|
for i in range(10):
|
|
|
|
log_message.log_time = time.time_ns()
|
|
|
|
file_cache.write_stdout(log_message)
|
|
|
|
stdio.write_stdout(log_message)
|
|
|
|
|
2023-12-03 16:36:01 +08:00
|
|
|
print("write 10 lines")
|
2023-11-05 19:54:34 +08:00
|
|
|
time.sleep(3)
|
2023-12-03 16:36:01 +08:00
|
|
|
print("exit")
|