1
0
mirror of https://github.com/Eyre-S/Coeur-Morny-Cono-python.git synced 2024-09-27 18:56:20 +08:00

use pyssage as logging backend

This commit is contained in:
A.C.Sukazyo Eyre 2023-05-11 20:40:32 +08:00
parent 5180739617
commit b8ec9169ab
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
8 changed files with 27 additions and 114 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Coeur-Morny-Cono-python
todo...

View File

@ -1,26 +0,0 @@
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

View File

@ -1,31 +0,0 @@
from datetime import datetime
import threading
from morny.morny_system import Coeur_Def
from .log import *
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")
def output (message:Log) :
echo = format_message(message)
print(echo)
if Coeur_Def.is_file_logging() :
log_file.write(echo+"\n")
log_file_archive.write(echo+"\n")
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

View File

@ -1,10 +0,0 @@
from logger.log import Log, LogLevels
from logger.log_appender import output
def trace (msg:str) : output(Log(msg, LogLevels.trace))
def debug (msg:str) : output(Log(msg, LogLevels.debug))
def info (msg:str) : output(Log(msg, LogLevels.info))
def warn(msg:str) : output(Log(msg, LogLevels.warn))
def error (msg:str) : output(Log(msg, LogLevels.error))
def fatal (msg:str) : output(Log(msg, LogLevels.fatal))

View File

@ -1,35 +1,21 @@
from logger import logger as logger_impl from pyssage.components.restrictions import RestrictionToLog, LevelRestriction
from pyssage.appender import ConsoleAppender
from pyssage.formatter import SimpleFormatter
from pyssage.log.log import levels
from pyssage.logger import Logger
class logger:
debug_mode: bool = False restriction: RestrictionToLog = LevelRestriction(levels.INFO)
@staticmethod logger: Logger = Logger(ConsoleAppender(SimpleFormatter()))
def trace (msg: str): logger.restrictions.append(restriction)
if (logger.debug_mode):
logger_impl.trace(msg)
@staticmethod
def debug (msg: str):
if (logger.debug_mode):
logger_impl.debug(msg)
@staticmethod
def info (msg: str):
logger_impl.info(msg)
@staticmethod
def warn (msg: str):
logger_impl.warn(msg)
@staticmethod
def error (msg: str):
logger_impl.error(msg)
@staticmethod
def fatal (msg: str):
logger_impl.fatal(msg)
def set_debug_mode(mode: bool): def set_debug_mode(mode: bool):
logger.debug_mode = mode if mode:
restriction.min_level = levels.ALL
else:
restriction.min_level = levels.INFO
def is_debug_mode () -> bool:
return restriction.min_level < levels.INFO

View File

@ -97,7 +97,7 @@ def main():
for __arg in _unknownArgs: for __arg in _unknownArgs:
logger.warn(f" {__arg}") logger.warn(f" {__arg}")
if (logger.debug_mode): if (log.is_debug_mode()):
logger.warn("Debug log output enabled.\n It may lower your performance, make sure that you are not in production environment.") logger.warn("Debug log output enabled.\n It may lower your performance, make sure that you are not in production environment.")
logger.debug("Debug log output enabled.") logger.debug("Debug log output enabled.")

View File

@ -5,15 +5,3 @@ def strm(*strs: str) -> str:
output += "\n" output += "\n"
output += strs[len(strs)-1] output += strs[len(strs)-1]
return output return output
# test for this
if __name__ == "__main__":
print(strm(
"Aaa",
" bbb",
" ccc",
"Xxx",
" yyy"
))

View File

@ -4,11 +4,14 @@ version = "0.1.2+coeur1.0.0-RC3.7"
description = "A Coeur-Morny-Cono rewrite by python3" description = "A Coeur-Morny-Cono rewrite by python3"
authors = ["Eyre_S <sukazyo@outlook.com>"] authors = ["Eyre_S <sukazyo@outlook.com>"]
readme = "README.md" readme = "README.md"
packages = [{include = "morny_coeur_python"}] packages = [
{include = "morny"}
]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.10" python = "^3.10"
python-telegram-bot = "^13.14" python-telegram-bot = "^13.14"
pyssage = { git = "https://github.com/suk-ws/pyssage", tag="0.1.0" }
[build-system] [build-system]