mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono-python.git
synced 2024-09-27 18:56:20 +08:00
完成了 morny java 所使用的 messiva 日志记录器的简单重构的 Log 模型和控制台输出格式化工具
This commit is contained in:
commit
29fed96a3b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
__run/
|
||||||
|
**__pycache__
|
26
logger/log.py
Normal file
26
logger/log.py
Normal file
@ -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
|
18
logger/log_appender.py
Normal file
18
logger/log_appender.py
Normal file
@ -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
|
||||||
|
|
0
logger/logger.py
Normal file
0
logger/logger.py
Normal file
4
morny/morny_coeur.py
Normal file
4
morny/morny_coeur.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class MornyCoeur :
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user