diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc940fb --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Coeur-Morny-Cono-python + +todo... diff --git a/logger/log.py b/logger/log.py deleted file mode 100644 index 19b968a..0000000 --- a/logger/log.py +++ /dev/null @@ -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 diff --git a/logger/log_appender.py b/logger/log_appender.py deleted file mode 100644 index eeced27..0000000 --- a/logger/log_appender.py +++ /dev/null @@ -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 - diff --git a/logger/logger.py b/logger/logger.py deleted file mode 100644 index 4da0fc1..0000000 --- a/logger/logger.py +++ /dev/null @@ -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)) diff --git a/morny/log.py b/morny/log.py index 9f46faa..7e84532 100644 --- a/morny/log.py +++ b/morny/log.py @@ -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 + + +restriction: RestrictionToLog = LevelRestriction(levels.INFO) + +logger: Logger = Logger(ConsoleAppender(SimpleFormatter())) +logger.restrictions.append(restriction) -class logger: - - debug_mode: bool = False - - @staticmethod - def trace (msg: str): - 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): - 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 diff --git a/morny/server_main.py b/morny/server_main.py index 2673716..ec3c2fd 100644 --- a/morny/server_main.py +++ b/morny/server_main.py @@ -97,7 +97,7 @@ def main(): for __arg in _unknownArgs: 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.debug("Debug log output enabled.") diff --git a/morny/util/str.py b/morny/util/str.py index 9417a49..415949d 100644 --- a/morny/util/str.py +++ b/morny/util/str.py @@ -4,16 +4,4 @@ def strm(*strs: str) -> str: output += strs[i] output += "\n" output += strs[len(strs)-1] - return output - -# test for this -if __name__ == "__main__": - - print(strm( - "Aaa", - " bbb", - " ccc", - "Xxx", - " yyy" - )) - \ No newline at end of file + return output \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a9bf125..270d1cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,11 +4,14 @@ version = "0.1.2+coeur1.0.0-RC3.7" description = "A Coeur-Morny-Cono rewrite by python3" authors = ["Eyre_S "] readme = "README.md" -packages = [{include = "morny_coeur_python"}] +packages = [ + {include = "morny"} +] [tool.poetry.dependencies] python = "^3.10" python-telegram-bot = "^13.14" +pyssage = { git = "https://github.com/suk-ws/pyssage", tag="0.1.0" } [build-system]