feat: use local logger (lib not dr logger)
This commit is contained in:
parent
ba4793acc8
commit
aa8a53e7b7
@ -52,7 +52,6 @@ class _DRStatus(Options):
|
||||
report_translate_not_found: bool = True
|
||||
use_multiprocess: bool = False
|
||||
use_cProfile: bool = False
|
||||
use_local_logging: bool = False
|
||||
|
||||
# tests
|
||||
playing: bool = False
|
||||
@ -78,7 +77,7 @@ class _DRStatus(Options):
|
||||
DR_status = _DRStatus()
|
||||
|
||||
|
||||
def load_logging():
|
||||
def load_logger():
|
||||
log_config_path = Path("./config/lndl-logger.toml")
|
||||
|
||||
import rtoml
|
||||
@ -98,9 +97,8 @@ def load_logging():
|
||||
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
|
||||
from lib_not_dr.loggers.config import read_config, get_logger
|
||||
read_config(logger_config)
|
||||
from lib_not_dr.loggers.config import get_logger
|
||||
logger = get_logger("main")
|
||||
logger.info("Logger config loaded", tag='DR-init')
|
||||
logger.info(f"DR status:\n{DR_status.as_markdown()}", tag='DR-init')
|
||||
@ -110,7 +108,7 @@ def load_logging():
|
||||
|
||||
# 读取日志配置
|
||||
# 也保证可以直接运行,不带日志 ( 因为有默认配置 )
|
||||
load_logging()
|
||||
load_logger()
|
||||
|
||||
|
||||
if DR_status.playing:
|
||||
|
@ -7,7 +7,6 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
import inspect
|
||||
import functools
|
||||
import traceback
|
||||
@ -43,8 +42,10 @@ from Difficult_Rocket.client.screen import DRDEBUGScreen
|
||||
from Difficult_Rocket.client.fps.fps_log import FpsLogger
|
||||
from Difficult_Rocket.exception.language import LanguageNotFound
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
logger = logging.getLogger("client")
|
||||
|
||||
logger = loggers.config.get_logger("client")
|
||||
|
||||
|
||||
class ClientOption(Options):
|
||||
@ -78,7 +79,7 @@ class Client:
|
||||
def __init__(self, game: "Game", net_mode="local"):
|
||||
start_time = time.time_ns()
|
||||
# logging
|
||||
self.logger = logging.getLogger("client")
|
||||
self.logger = loggers.get_logger("client")
|
||||
self.logger.info(tr().client.setup.start())
|
||||
# config
|
||||
self.config = ClientOption()
|
||||
@ -128,7 +129,7 @@ def pyglet_load_fonts_folder(folder) -> None:
|
||||
if not font_path.exists():
|
||||
font_path.mkdir(parents=True)
|
||||
return None
|
||||
logger.info(tr().client.load.font.start().format(font_path))
|
||||
logger.info(tr().client.load.font.start().format(font_path), tag='font')
|
||||
start_time = time.time_ns()
|
||||
for dir_path, dir_names, file_names in os.walk(font_path):
|
||||
dir_path = Path(dir_path)
|
||||
@ -136,7 +137,7 @@ def pyglet_load_fonts_folder(folder) -> None:
|
||||
file_name = Path(file_name)
|
||||
if file_name.suffix in (".ttf", ".otf"):
|
||||
logger.debug(
|
||||
tr().client.load.font.file().format(str(dir_path / file_name))
|
||||
tr().client.load.font.file().format(str(dir_path / file_name)), tag='font'
|
||||
)
|
||||
try:
|
||||
pyglet.font.add_file(str(dir_path / file_name))
|
||||
@ -148,7 +149,7 @@ def pyglet_load_fonts_folder(folder) -> None:
|
||||
)
|
||||
end_time = time.time_ns()
|
||||
use_time = end_time - start_time
|
||||
logger.info(tr().client.load.font.use_time().format(use_time / 1000000000))
|
||||
logger.info(tr().client.load.font.use_time().format(use_time / 1000000000), tag='font')
|
||||
|
||||
|
||||
def _call_back(call_back: Callable) -> Callable:
|
||||
@ -240,7 +241,7 @@ class ClientWindow(Window):
|
||||
start_time = time.time_ns()
|
||||
super().__init__(*args, **kwargs)
|
||||
# logging
|
||||
self.logger = logging.getLogger("client")
|
||||
self.logger = loggers.get_logger("client")
|
||||
self.logger.info(tr().window.setup.start())
|
||||
# value
|
||||
self.game = game
|
||||
@ -307,10 +308,10 @@ class ClientWindow(Window):
|
||||
# TODO: wait for pyglet 2.1
|
||||
pyglet.app.run(float(self.SPF))
|
||||
except KeyboardInterrupt:
|
||||
self.logger.warning("==========client stop. KeyboardInterrupt info==========")
|
||||
self.logger.warn("==========client stop. KeyboardInterrupt info==========", tag="starter")
|
||||
traceback.print_exc()
|
||||
self.logger.warning(
|
||||
"==========client stop. KeyboardInterrupt info end=========="
|
||||
self.logger.warn(
|
||||
"==========client stop. KeyboardInterrupt info end==========", tag="starter"
|
||||
)
|
||||
self.dispatch_event("on_close", "input")
|
||||
sys.exit(0)
|
||||
|
@ -11,28 +11,18 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
# import time
|
||||
import logging
|
||||
|
||||
# import traceback
|
||||
import logging.config
|
||||
import multiprocessing
|
||||
|
||||
# from io import StringIO
|
||||
# from pathlib import Path
|
||||
from typing import List, Optional, Dict
|
||||
|
||||
# from Difficult_Rocket.utils import tools
|
||||
from Difficult_Rocket.api.types import Options
|
||||
|
||||
# from Difficult_Rocket.utils.translate import tr
|
||||
# from Difficult_Rocket.runtime import DR_runtime
|
||||
from Difficult_Rocket.mod.loader import ModManager
|
||||
from Difficult_Rocket.utils.thread import new_thread
|
||||
|
||||
# from Difficult_Rocket.crash import write_info_to_cache
|
||||
from Difficult_Rocket import client, server, DR_status
|
||||
|
||||
from lib_not_dr.loggers import config
|
||||
from lib_not_dr.loggers.logger import Logger
|
||||
|
||||
|
||||
class Console(Options):
|
||||
name = "python stdin console"
|
||||
@ -75,7 +65,7 @@ class Game(Options):
|
||||
console_class: Console = Console
|
||||
|
||||
main_config: Dict
|
||||
logger: logging.Logger
|
||||
logger: Logger
|
||||
|
||||
mod_manager: ModManager
|
||||
|
||||
@ -84,9 +74,6 @@ class Game(Options):
|
||||
|
||||
def init_mods(self) -> None:
|
||||
"""验证/加载 mod"""
|
||||
from Difficult_Rocket.mod import loader as mod_loader
|
||||
|
||||
mod_loader.logger = logging.getLogger("mod_manager")
|
||||
self.mod_manager = ModManager()
|
||||
mod_class = self.mod_manager.load_mods()
|
||||
self.mod_manager.init_mods(mod_class)
|
||||
@ -120,7 +107,7 @@ class Game(Options):
|
||||
self.server = server.Server(net_mode="local")
|
||||
|
||||
def init(self, **kwargs) -> bool:
|
||||
self.logger = logging.getLogger("main")
|
||||
self.logger = config.get_logger("main")
|
||||
self.load_file()
|
||||
self.setup()
|
||||
self.log_env()
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
import traceback
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
@ -16,9 +15,11 @@ from Difficult_Rocket.mod.api import ModInfo
|
||||
from Difficult_Rocket.utils.translate import tr
|
||||
from Difficult_Rocket.api.types import Options
|
||||
|
||||
from lib_not_dr.loggers import config
|
||||
|
||||
Game = TypeVar("Game")
|
||||
|
||||
logger = logging.getLogger("mod_manager")
|
||||
logger = config.get_logger_from_old("mod_manager", "client")
|
||||
ONE_FILE_SUFFIX = (".py", ".pyc", ".pyd")
|
||||
PACKAGE_SUFFIX = (".pyz", ".zip", ".dr_mod")
|
||||
|
||||
@ -91,14 +92,14 @@ class ModManager(Options):
|
||||
if not hasattr(loading_mod, "mod_class") or not issubclass(
|
||||
loading_mod.mod_class, ModInfo
|
||||
):
|
||||
logger.warning(tr().mod.load.faild.no_mod_class().format(mod_path))
|
||||
logger.warn(tr().mod.load.faild.no_mod_class().format(mod_path))
|
||||
return None
|
||||
mod_class: type(ModInfo) = loading_mod.mod_class # 获取 mod 类
|
||||
if mod_class.mod_id not in self.find_mod_paths:
|
||||
self.find_mod_paths[mod_class.mod_id] = mod_path
|
||||
return mod_class
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
logger.warn(
|
||||
tr().mod.load.faild.error().format(mod_path, traceback.format_exc())
|
||||
)
|
||||
return None
|
||||
@ -193,7 +194,7 @@ class ModManager(Options):
|
||||
not (mod_class := self.loaded_mod_modules.get(mod_id))
|
||||
and (mod_class := self.get_mod_module(mod_id)) is None
|
||||
):
|
||||
logger.warning(tr().mod.unload.faild.not_find().format(mod_id))
|
||||
logger.warn(tr().mod.unload.faild.not_find().format(mod_id))
|
||||
return None
|
||||
try:
|
||||
mod_class.on_unload(game=game)
|
||||
@ -218,7 +219,7 @@ class ModManager(Options):
|
||||
return
|
||||
mod_class: Optional[ModInfo] = None
|
||||
if unload.mod_id not in self.find_mod_paths:
|
||||
logger.warning(tr().mod.reload.faild.not_find().format(unload.mod_id))
|
||||
logger.warn(tr().mod.reload.faild.not_find().format(unload.mod_id))
|
||||
paths = self.find_mods_in_path()
|
||||
for path in paths:
|
||||
mod_class = self.load_mod(path)
|
||||
|
@ -13,13 +13,12 @@ gitee: @shenjackyuanjie
|
||||
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
# import multiprocessing
|
||||
|
||||
from Difficult_Rocket.utils import tools
|
||||
from Difficult_Rocket.utils.translate import tr
|
||||
# from Difficult_Rocket.api.delivery import Delivery
|
||||
# from Difficult_Rocket.utils.new_thread import new_thread
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
|
||||
# TODO 改变服务端启动逻辑 0.6.0(划掉 0.8.0)会写完的(
|
||||
@ -29,7 +28,7 @@ class Server:
|
||||
def __init__(self, net_mode="local"):
|
||||
start_time = time.time()
|
||||
# logging
|
||||
self.logger = logging.getLogger("server")
|
||||
self.logger = loggers.config.get_logger("server")
|
||||
self.logger.info(tr().server.setup.start())
|
||||
# value
|
||||
self.process_id = os.getpid()
|
||||
|
@ -17,7 +17,6 @@ import time
|
||||
import math
|
||||
import json
|
||||
import rtoml
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
from pathlib import Path
|
||||
@ -27,28 +26,30 @@ from defusedxml.ElementTree import parse
|
||||
|
||||
from Difficult_Rocket.exception.unsupport import NoMoreJson5
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
# logger
|
||||
tools_logger = logging.getLogger("tools")
|
||||
tools_logger = loggers.config.get_logger("tools")
|
||||
"""
|
||||
file config
|
||||
"""
|
||||
|
||||
file_error = {
|
||||
FileNotFoundError: "no {filetype} file was founded!:\n file name: {filename}\n file_type: {filetype}\n stack: {stack}",
|
||||
KeyError: "no stack in {filetype} file {filename} was found! \n file type: {} \n file name: {} \n stack: {stack}",
|
||||
Exception: "get some {error_type} when read {filetype} file {filename}! \n file type: {} \n file name: {} \n stack: {stack}",
|
||||
KeyError: "no stack in {filetype} file {filename} was found! \n file type: {} \n file name: {} \n stack: {stack}",
|
||||
Exception: "get some {error_type} when read {filetype} file {filename}! \n file type: {} \n file name: {} \n stack: {stack}",
|
||||
}
|
||||
|
||||
|
||||
def load_file(
|
||||
file_name: Union[str, Path],
|
||||
stack: Optional[Union[str, list, dict]] = None,
|
||||
raise_error: Optional[bool] = True,
|
||||
encoding: Optional[str] = "utf-8",
|
||||
file_name: Union[str, Path],
|
||||
stack: Optional[Union[str, list, dict]] = None,
|
||||
raise_error: Optional[bool] = True,
|
||||
encoding: Optional[str] = "utf-8",
|
||||
) -> Union[dict, ElementTree.ElementTree]:
|
||||
if isinstance(file_name, Path):
|
||||
file_name = str(file_name)
|
||||
f_type = file_name[file_name.rfind(".") + 1 :] # 从最后一个.到末尾 (截取文件格式)
|
||||
f_type = file_name[file_name.rfind(".") + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
get_file = NotImplementedError("解析失败,请检查文件类型/文件内容/文件是否存在!")
|
||||
try:
|
||||
if f_type == "xml":
|
||||
@ -95,7 +96,7 @@ def load_file(
|
||||
|
||||
|
||||
def save_dict_file(file_name: str, data: dict, encoding: str = "utf-8") -> bool:
|
||||
f_type = file_name[file_name.rfind(".") + 1 :] # 从最后一个.到末尾 (截取文件格式)
|
||||
f_type = file_name[file_name.rfind(".") + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
try:
|
||||
if (f_type == "config") or (f_type == "conf") or (f_type == "ini"):
|
||||
return False
|
||||
@ -201,36 +202,6 @@ def format_bool(thing) -> bool:
|
||||
raise TypeError("Need a 'like bool' not a {}".format(thing))
|
||||
|
||||
|
||||
level_ = [
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"ERROR",
|
||||
"CRITICAL",
|
||||
logging.DEBUG,
|
||||
logging.INFO,
|
||||
logging.WARNING,
|
||||
logging.ERROR,
|
||||
logging.CRITICAL,
|
||||
]
|
||||
|
||||
|
||||
def log_level(level):
|
||||
if level in level_:
|
||||
if (level == "DEBUG") or (level == logging.DEBUG):
|
||||
return logging.DEBUG
|
||||
if (level == "INFO") or (level == logging.INFO):
|
||||
return logging.INFO
|
||||
if (level == "WARNING") or (level == logging.WARNING):
|
||||
return logging.WARNING
|
||||
if (level == "ERROR") or (level == logging.ERROR):
|
||||
return logging.ERROR
|
||||
if (level == "CRITICAL") or (level == logging.CRITICAL):
|
||||
return logging.CRITICAL
|
||||
else:
|
||||
raise ValueError("Need a like logging.level thing not anything else")
|
||||
|
||||
|
||||
# linear_algebra
|
||||
|
||||
|
||||
|
@ -13,6 +13,13 @@
|
||||
- `name` = `DR Option` -> `DR Status`
|
||||
- 这毛病属实是没想到, 之前一直没发现
|
||||
|
||||
### Rework
|
||||
|
||||
- 将 `logging` 的依赖改为 `lib_not_dr.loggers`
|
||||
- 以后都用 `lib_not_dr` 的 logger 了
|
||||
- Change the dependency of `logging` to `lib_not_dr.loggers`
|
||||
- Use `lib_not_dr` logger in the future
|
||||
|
||||
### Add
|
||||
|
||||
- 添加内置依赖: `lib-not-dr`
|
||||
|
@ -4,7 +4,6 @@
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
import traceback
|
||||
|
||||
@ -16,9 +15,11 @@ from Difficult_Rocket.api.mod import ModInfo
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
from Difficult_Rocket.api.types import Options, Version
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
DR_rust_version = Version("0.2.23.0") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
|
||||
logger = logging.getLogger("client.dr_game")
|
||||
logger = loggers.config.get_logger_from_old("client.dr_game", "client")
|
||||
|
||||
|
||||
class _DR_mod_runtime(Options): # NOQA
|
||||
|
Loading…
Reference in New Issue
Block a user