From 63cf2ba1e62241adb32beff4a97c87b1f3aef9f2 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 13 Dec 2023 09:43:29 +0800 Subject: [PATCH] =?UTF-8?q?enhance=20|=20=E5=8F=AA=E6=9C=89=E7=9C=9F?= =?UTF-8?q?=E6=AD=A3=E7=94=A8=E4=B8=8A=E9=85=8D=E7=BD=AE=E4=BA=86=E6=89=8D?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E4=B9=8B=E5=89=8D=E5=86=99=E7=9A=84=E8=BF=99?= =?UTF-8?q?=E5=A0=86=E7=8E=A9=E6=84=8F=E5=A4=9A=E7=A6=BB=E8=B0=B1=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Difficult_Rocket/__init__.py | 43 ++++++++++----- Difficult_Rocket/data/log_config.py | 86 +++++++++++++++++++++++++++++ config/lndl-logger.toml | 8 +-- libs/lib_not_dr | 2 +- libs/pyglet | 2 +- 5 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 Difficult_Rocket/data/log_config.py diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index e2dcdf7..8d0019b 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -5,7 +5,7 @@ # ------------------------------- import time -import logging.config +# import logging.config from pathlib import Path from Difficult_Rocket.api.types import Options, Version @@ -21,11 +21,12 @@ __all__ = [ "DR_status", # folder "api", + "data", "client", - "server", "command", "crash", "exception", + "server", "mod", "utils", # file @@ -37,7 +38,7 @@ __all__ = [ ] -class _DR_status(Options): +class _DRStatus(Options): """ DR 的特性开关 / 基本状态 """ @@ -76,20 +77,36 @@ class _DR_status(Options): return round(12 * self.gui_scale) -DR_status = _DR_status() +DR_status = _DRStatus() def load_logging(): - with open("./config/logger.toml") as f: - import rtoml + # with open("./config/logger.toml") as f: + # import rtoml + # + # logger_config = rtoml.load(f) + # log_path = logger_config["handlers"]["file"]["filename"] + # log_path = f"logs/{log_path.format(time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time_ns() / 1000_000_000)))}" + # if not Path("logs/").is_dir(): + # Path("logs/").mkdir() + # logger_config["handlers"]["file"]["filename"] = log_path + # logging.config.dictConfig(logger_config) + log_config_path = Path("./config/lndl-logger.toml") - logger_config = rtoml.load(f) - log_path = logger_config["handlers"]["file"]["filename"] - log_path = f"logs/{log_path.format(time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time_ns() / 1000_000_000)))}" - if not Path("logs/").is_dir(): - Path("logs/").mkdir() - logger_config["handlers"]["file"]["filename"] = log_path - logging.config.dictConfig(logger_config) + import rtoml + + if not log_config_path.is_file(): + # 生成默认配置文件 + from Difficult_Rocket.data import log_config + log_config_path.write_text(log_config.default_config) + logger_config = rtoml.loads(log_config.default_config) + else: + # 读取配置文件 + with open(log_config_path, encoding='utf-8') as f: + logger_config = rtoml.load(f) + # 输入 lndl 进行配置 + from lib_not_dr.loggers.config import read_config + read_config(logger_config) load_logging() diff --git a/Difficult_Rocket/data/log_config.py b/Difficult_Rocket/data/log_config.py new file mode 100644 index 0000000..7610a05 --- /dev/null +++ b/Difficult_Rocket/data/log_config.py @@ -0,0 +1,86 @@ +# ------------------------------- +# Difficult Rocket +# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com +# All rights reserved +# ------------------------------- + + +default_config = """ +config_version = 1 + +[Logger] + + [Logger.client] + # 日志名称 + logger_name = "client" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + + [Logger.server] + # 日志名称 + logger_name = "server" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + + [Logger.main] + # 日志名称 + logger_name = "main" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + +[Formatter] + + [Formatter.main_formatter] + # 格式化器名称 + class = "MainFormatter" + # 格式化器参数 + time_format = "%Y-%m-%d %H:%M:%S" + msec_time_format = "{}-{:03d}" + use_absolute_path = false + + [Formatter.std_formatter] + class = "StdFormatter" + sub_formatter = ["main_formatter"] + default_template = "[{log_time}][{level}]|{logger_name}:{logger_tag}|{messages}" + +[Outstream] + + [Outstream.std_out] + # 输出流名称 + class = "StdioOutputStream" + # 输出流参数 + formatter = "std_formatter" + use_stderr = false + # or true + level_name = "debug" + # or 'DEBUG' + # or level = 10 + + [Outstream.file_out] + class = "FileCacheOutputStream" + + level = 10 + # or level_name = 'DEBUG' + # or level_name = 'debug' + formatter = "std_formatter" + flush_count_limit = 10 + # 5 条日志刷新一次 + flush_time_limit = 5 + # 5 秒刷新一次 + # or flush_time_limit = 0.5 + file_path = "./logs" + file_name = "dr-{time}.log" +""" + +# 整的跟 export 一样 +# fmt: off +__all__ = [ + "default_config" +] +# fmt: on diff --git a/config/lndl-logger.toml b/config/lndl-logger.toml index 3ee039a..6b857df 100644 --- a/config/lndl-logger.toml +++ b/config/lndl-logger.toml @@ -34,10 +34,10 @@ config_version = 1 # 格式化器参数 time_format = "%Y-%m-%d %H:%M:%S" msec_time_format = "{}-{:03d}" - use_absolut_path = false + use_absolute_path = false [Formatter.std_formatter] - formatter_class = "StdFormatter" + class = "StdFormatter" sub_formatter = ["main_formatter"] default_template = "[{log_time}][{level}]|{logger_name}:{logger_tag}|{messages}" @@ -45,7 +45,7 @@ config_version = 1 [Outstream.std_out] # 输出流名称 - class = "StdOutputStream" + class = "StdioOutputStream" # 输出流参数 formatter = "std_formatter" use_stderr = false @@ -67,4 +67,4 @@ config_version = 1 # 5 秒刷新一次 # or flush_time_limit = 0.5 file_path = "./logs" - file_name = "%s-dr.log" + file_name = "dr-{time}.log" diff --git a/libs/lib_not_dr b/libs/lib_not_dr index 544c180..a4e63ef 160000 --- a/libs/lib_not_dr +++ b/libs/lib_not_dr @@ -1 +1 @@ -Subproject commit 544c180e728d1b1f7942cb7874f6e579c1acc02b +Subproject commit a4e63ef73f6d25a7840c88dc6f4286157785f41e diff --git a/libs/pyglet b/libs/pyglet index e5b5e24..7df9ee8 160000 --- a/libs/pyglet +++ b/libs/pyglet @@ -1 +1 @@ -Subproject commit e5b5e24807687b1a12dca73ce3055a2745d38cf9 +Subproject commit 7df9ee869242f482579f1aa0ed5c61e39c4a444f