enhance | 只有真正用上配置了才发现之前写的这堆玩意多离谱(
This commit is contained in:
parent
df4105ec61
commit
63cf2ba1e6
@ -5,7 +5,7 @@
|
|||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import logging.config
|
# import logging.config
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from Difficult_Rocket.api.types import Options, Version
|
from Difficult_Rocket.api.types import Options, Version
|
||||||
@ -21,11 +21,12 @@ __all__ = [
|
|||||||
"DR_status",
|
"DR_status",
|
||||||
# folder
|
# folder
|
||||||
"api",
|
"api",
|
||||||
|
"data",
|
||||||
"client",
|
"client",
|
||||||
"server",
|
|
||||||
"command",
|
"command",
|
||||||
"crash",
|
"crash",
|
||||||
"exception",
|
"exception",
|
||||||
|
"server",
|
||||||
"mod",
|
"mod",
|
||||||
"utils",
|
"utils",
|
||||||
# file
|
# file
|
||||||
@ -37,7 +38,7 @@ __all__ = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class _DR_status(Options):
|
class _DRStatus(Options):
|
||||||
"""
|
"""
|
||||||
DR 的特性开关 / 基本状态
|
DR 的特性开关 / 基本状态
|
||||||
"""
|
"""
|
||||||
@ -76,20 +77,36 @@ class _DR_status(Options):
|
|||||||
return round(12 * self.gui_scale)
|
return round(12 * self.gui_scale)
|
||||||
|
|
||||||
|
|
||||||
DR_status = _DR_status()
|
DR_status = _DRStatus()
|
||||||
|
|
||||||
|
|
||||||
def load_logging():
|
def load_logging():
|
||||||
with open("./config/logger.toml") as f:
|
# 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")
|
||||||
|
|
||||||
import rtoml
|
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)
|
logger_config = rtoml.load(f)
|
||||||
log_path = logger_config["handlers"]["file"]["filename"]
|
# 输入 lndl 进行配置
|
||||||
log_path = f"logs/{log_path.format(time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time_ns() / 1000_000_000)))}"
|
from lib_not_dr.loggers.config import read_config
|
||||||
if not Path("logs/").is_dir():
|
read_config(logger_config)
|
||||||
Path("logs/").mkdir()
|
|
||||||
logger_config["handlers"]["file"]["filename"] = log_path
|
|
||||||
logging.config.dictConfig(logger_config)
|
|
||||||
|
|
||||||
|
|
||||||
load_logging()
|
load_logging()
|
||||||
|
86
Difficult_Rocket/data/log_config.py
Normal file
86
Difficult_Rocket/data/log_config.py
Normal file
@ -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
|
@ -34,10 +34,10 @@ config_version = 1
|
|||||||
# 格式化器参数
|
# 格式化器参数
|
||||||
time_format = "%Y-%m-%d %H:%M:%S"
|
time_format = "%Y-%m-%d %H:%M:%S"
|
||||||
msec_time_format = "{}-{:03d}"
|
msec_time_format = "{}-{:03d}"
|
||||||
use_absolut_path = false
|
use_absolute_path = false
|
||||||
|
|
||||||
[Formatter.std_formatter]
|
[Formatter.std_formatter]
|
||||||
formatter_class = "StdFormatter"
|
class = "StdFormatter"
|
||||||
sub_formatter = ["main_formatter"]
|
sub_formatter = ["main_formatter"]
|
||||||
default_template = "[{log_time}][{level}]|{logger_name}:{logger_tag}|{messages}"
|
default_template = "[{log_time}][{level}]|{logger_name}:{logger_tag}|{messages}"
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ config_version = 1
|
|||||||
|
|
||||||
[Outstream.std_out]
|
[Outstream.std_out]
|
||||||
# 输出流名称
|
# 输出流名称
|
||||||
class = "StdOutputStream"
|
class = "StdioOutputStream"
|
||||||
# 输出流参数
|
# 输出流参数
|
||||||
formatter = "std_formatter"
|
formatter = "std_formatter"
|
||||||
use_stderr = false
|
use_stderr = false
|
||||||
@ -67,4 +67,4 @@ config_version = 1
|
|||||||
# 5 秒刷新一次
|
# 5 秒刷新一次
|
||||||
# or flush_time_limit = 0.5
|
# or flush_time_limit = 0.5
|
||||||
file_path = "./logs"
|
file_path = "./logs"
|
||||||
file_name = "%s-dr.log"
|
file_name = "dr-{time}.log"
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 544c180e728d1b1f7942cb7874f6e579c1acc02b
|
Subproject commit a4e63ef73f6d25a7840c88dc6f4286157785f41e
|
@ -1 +1 @@
|
|||||||
Subproject commit e5b5e24807687b1a12dca73ce3055a2745d38cf9
|
Subproject commit 7df9ee869242f482579f1aa0ed5c61e39c4a444f
|
Loading…
Reference in New Issue
Block a user