2022-09-25 21:59:45 +08:00
|
|
|
from datetime import datetime
|
|
|
|
import threading
|
2022-09-27 22:44:40 +08:00
|
|
|
|
2023-05-06 23:44:08 +08:00
|
|
|
from morny.morny_system import Coeur_Def
|
2022-09-25 21:59:45 +08:00
|
|
|
from .log import *
|
|
|
|
|
2022-09-27 22:44:40 +08:00
|
|
|
if Coeur_Def.is_file_logging() :
|
|
|
|
log_file_archive = open(f"./logs/{time.strftime('%Y-%m-%d-%H:%M:%S.log', time.localtime())}", "x")
|
|
|
|
log_file = open("./log__latest.log", "a")
|
|
|
|
|
2022-09-26 16:08:18 +08:00
|
|
|
def output (message:Log) :
|
2022-09-27 22:44:40 +08:00
|
|
|
echo = format_message(message)
|
|
|
|
print(echo)
|
|
|
|
if Coeur_Def.is_file_logging() :
|
|
|
|
log_file.write(echo+"\n")
|
|
|
|
log_file_archive.write(echo+"\n")
|
2022-09-26 16:08:18 +08:00
|
|
|
|
2022-09-25 21:59:45 +08:00
|
|
|
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
|
|
|
|
|