commit 29fed96a3b838100996edb472cfd7cf7372faf58 Author: Eyre_S Date: Sun Sep 25 21:59:45 2022 +0800 完成了 morny java 所使用的 messiva 日志记录器的简单重构的 Log 模型和控制台输出格式化工具 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a64d12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__run/ +**__pycache__ diff --git a/logger/log.py b/logger/log.py new file mode 100644 index 0000000..19b968a --- /dev/null +++ b/logger/log.py @@ -0,0 +1,26 @@ +import time + +class LogLevel: + def __init__(self, level:float, name:str) : + self.level = level + self.name = name + # def level (self) -> float : return self.level + # def name (self) -> str : return self.name + +class LogLevels: + trace:LogLevel = LogLevel(-1, "TRAC") + debug:LogLevel = LogLevel(0.1, "DBUG") + info:LogLevel = LogLevel(0, "INFO") + warn:LogLevel = LogLevel(0.5, "WARN") + error:LogLevel = LogLevel(1, "ERRO") + fatal:LogLevel = LogLevel(10, "FTAL") + null:LogLevel = LogLevel(0, "NULL") + +class Log: + def __init__ (self, message:str, level:LogLevel) : + self.timestamp = time.time_ns() + self.level = level + self.message = message + # def timestamp (self) -> int : return self.timestamp + # def level (self) -> LogLevel : return self.level + # def message (self) -> str : return self.message diff --git a/logger/log_appender.py b/logger/log_appender.py new file mode 100644 index 0000000..a5a0da4 --- /dev/null +++ b/logger/log_appender.py @@ -0,0 +1,18 @@ +from datetime import datetime +import threading +from .log import * + +def format_message (log:Log) -> str : + + origins = log.message.split("\n") + + message = "" + message += f"[{datetime.fromtimestamp(log.timestamp/1000/1000/1000).strftime('%Y-%m-%d/%H:%M:%S:%f')}]" + \ + f"[{threading.current_thread().name }]" + promptNewLine = "'"*len(message) + message += f"[{log.level.name}]{origins[0]}" + for i in range(len(origins)-1) : + message += f"\n{promptNewLine}[{log.level.name}]{origins[i+1]}" + + return message + diff --git a/logger/logger.py b/logger/logger.py new file mode 100644 index 0000000..e69de29 diff --git a/morny/morny_coeur.py b/morny/morny_coeur.py new file mode 100644 index 0000000..c8de17f --- /dev/null +++ b/morny/morny_coeur.py @@ -0,0 +1,4 @@ +class MornyCoeur : + + + \ No newline at end of file diff --git a/start.py b/start.py new file mode 100644 index 0000000..e69de29