Compare commits

...

3 Commits

Author SHA1 Message Date
1815464df1
sync lndl 2023-12-14 14:00:42 +08:00
2b40562296
add settag for logger 2023-12-14 11:16:40 +08:00
960f524f95
Log | add tag for client logging 2023-12-14 09:38:03 +08:00
4 changed files with 35 additions and 31 deletions

View File

@ -78,7 +78,7 @@ class Client:
def __init__(self, game: "Game", net_mode="local"): def __init__(self, game: "Game", net_mode="local"):
start_time = time.time_ns() start_time = time.time_ns()
# logging # logging
self.logger = loggers.get_logger("client") self.logger = loggers.get_logger("client").set_tag("client")
self.logger.info(tr().client.setup.start()) self.logger.info(tr().client.setup.start())
# config # config
self.config = ClientOption() self.config = ClientOption()
@ -243,7 +243,7 @@ class ClientWindow(Window):
start_time = time.time_ns() start_time = time.time_ns()
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# logging # logging
self.logger = loggers.get_logger("client") self.logger = loggers.get_logger("client").set_tag("window")
self.logger.info(tr().window.setup.start()) self.logger.info(tr().window.setup.start())
# value # value
self.game = game self.game = game
@ -427,7 +427,7 @@ class ClientWindow(Window):
self.logger.info(tr().language_set_to()) self.logger.info(tr().language_set_to())
except LanguageNotFound: except LanguageNotFound:
self.logger.info( self.logger.info(
tr().language_available().format(os.listdir("./config/lang")) tr().language_available().format(os.listdir("./config/lang")), tag="command"
) )
self.save_info() self.save_info()
elif command.find("mods"): elif command.find("mods"):
@ -435,18 +435,18 @@ class ClientWindow(Window):
self.logger.info(tr().mod.list()) self.logger.info(tr().mod.list())
for mod in self.game.mod_manager.loaded_mod_modules.values(): for mod in self.game.mod_manager.loaded_mod_modules.values():
self.logger.info( self.logger.info(
f"mod: {mod.name} id: {mod.mod_id} version: {mod.version}" f"mod: {mod.name} id: {mod.mod_id} version: {mod.version}", tag="command"
) )
elif command.find("reload"): elif command.find("reload"):
if not len(command.text) == 0: if not len(command.text) == 0:
print(f"reload mod: |{command.text}|") print(f"reload mod: |{command.text}|")
self.game.mod_manager.reload_mod(command.text, game=self.game) self.game.mod_manager.reload_mod(command.text, game=self.game)
else: else:
logger.info(tr().window.command.mods.reload.no_mod_id()) self.logger.info(tr().window.command.mods.reload.no_mod_id(), tag="command")
@_call_screen_after @_call_screen_after
def on_message(self, message: line.CommandText): def on_message(self, message: line.CommandText):
self.logger.info(tr().window.message.text().format(message)) self.logger.info(tr().window.message.text().format(message), tag="message")
""" """
keyboard and mouse input keyboard and mouse input
@ -489,7 +489,7 @@ class ClientWindow(Window):
self.logger.debug( self.logger.debug(
tr() tr()
.window.mouse.press() .window.mouse.press()
.format([x, y], tr().window.mouse[mouse.buttons_string(button)]()) .format([x, y], tr().window.mouse[mouse.buttons_string(button)]()), tag="mouse"
) )
@_call_screen_after @_call_screen_after
@ -497,7 +497,7 @@ class ClientWindow(Window):
self.logger.debug( self.logger.debug(
tr() tr()
.window.mouse.release() .window.mouse.release()
.format([x, y], tr().window.mouse[mouse.buttons_string(button)]()) .format([x, y], tr().window.mouse[mouse.buttons_string(button)]()), tag="mouse"
) )
@_call_screen_after @_call_screen_after
@ -511,7 +511,7 @@ class ClientWindow(Window):
self.logger.debug( self.logger.debug(
tr() tr()
.window.key.press() .window.key.press()
.format(key.symbol_string(symbol), key.modifiers_string(modifiers)) .format(key.symbol_string(symbol), key.modifiers_string(modifiers)), tag="key"
) )
@_call_screen_after @_call_screen_after
@ -519,7 +519,7 @@ class ClientWindow(Window):
self.logger.debug( self.logger.debug(
tr() tr()
.window.key.release() .window.key.release()
.format(key.symbol_string(symbol), key.modifiers_string(modifiers)) .format(key.symbol_string(symbol), key.modifiers_string(modifiers)), tag="key"
) )
@_call_screen_after @_call_screen_after
@ -529,36 +529,36 @@ class ClientWindow(Window):
@_call_screen_after @_call_screen_after
def on_text(self, text): def on_text(self, text):
if text == "\r": if text == "\r":
self.logger.debug(tr().window.text.new_line()) self.logger.debug(tr().window.text.new_line(), tag="text")
else: else:
self.logger.debug(tr().window.text.input().format(text)) self.logger.debug(tr().window.text.input().format(text), tag="text")
if text == "t": if text == "t":
self.input_box.enabled = True self.input_box.enabled = True
@_call_screen_after @_call_screen_after
def on_text_motion(self, motion): def on_text_motion(self, motion):
motion_string = key.motion_string(motion) motion_string = key.motion_string(motion)
self.logger.debug(tr().window.text.motion().format(motion_string)) self.logger.debug(tr().window.text.motion().format(motion_string), tag="text")
@_call_screen_after @_call_screen_after
def on_text_motion_select(self, motion): def on_text_motion_select(self, motion):
motion_string = key.motion_string(motion) motion_string = key.motion_string(motion)
self.logger.debug(tr().window.text.motion_select().format(motion_string)) self.logger.debug(tr().window.text.motion_select().format(motion_string), tag="text")
@_call_screen_before @_call_screen_before
def on_close(self, source: str = "window") -> None: def on_close(self, source: str = "window") -> None:
self.game.dispatch_mod_event( self.game.dispatch_mod_event(
"on_close", game=self.game, client=self, source=source "on_close", game=self.game, client=self, source=source
) )
self.logger.info(tr().window.game.stop_get().format(tr().game[source]())) self.logger.info(tr().window.game.stop_get().format(tr().game[source]()), tag="window")
self.logger.info(tr().window.game.stop()) self.logger.info(tr().window.game.stop(), tag="window")
# self.fps_log.check_list = False # self.fps_log.check_list = False
DR_runtime.running = False DR_runtime.running = False
if self.run_input: if self.run_input:
self.run_input = False self.run_input = False
self.save_info() self.save_info()
super().on_close() super().on_close()
self.logger.info(tr().window.game.end()) self.logger.info(tr().window.game.end(), tag="window")
ClientWindow.register_event_type("on_command") ClientWindow.register_event_type("on_command")

View File

@ -37,6 +37,9 @@ class ModManager(Options):
find_mod_paths: Dict[str, Path] = {} find_mod_paths: Dict[str, Path] = {}
loaded_mod_modules: Dict[str, ModInfo] = {} loaded_mod_modules: Dict[str, ModInfo] = {}
def init(self, **kwargs) -> bool:
self.logger = config.get_logger_from_old("mod_manager", "client")
def get_mod_module(self, mod_name: str) -> Optional[ModInfo]: def get_mod_module(self, mod_name: str) -> Optional[ModInfo]:
""" """
获取指定 mod 的模块 获取指定 mod 的模块
@ -61,7 +64,7 @@ class ModManager(Options):
try: try:
getattr(mod, event_name)(*args, **kwargs) getattr(mod, event_name)(*args, **kwargs)
except Exception as e: except Exception as e:
logger.error( self.logger.error(
tr() tr()
.mod.event.error() .mod.event.error()
.format(mod, event_name, e, traceback.format_exc()) .format(mod, event_name, e, traceback.format_exc())
@ -73,6 +76,7 @@ class ModManager(Options):
:param mod_path: mod 的路径 :param mod_path: mod 的路径
:return: :return:
""" """
logger = self.logger.set_tag("load")
if not mod_path.exists(): if not mod_path.exists():
logger.error(tr().mod.load.faild.not_exist().format(mod_path), tag="load") logger.error(tr().mod.load.faild.not_exist().format(mod_path), tag="load")
return None return None
@ -134,7 +138,7 @@ class ModManager(Options):
): ):
# 文件夹 mod # 文件夹 mod
mods_path.append(mod) mods_path.append(mod)
logger.info( self.logger.info(
tr().mod.finded().format(len(mods_path), time.time() - start_time), tag="find" tr().mod.finded().format(len(mods_path), time.time() - start_time), tag="find"
) )
return mods_path return mods_path
@ -154,7 +158,7 @@ class ModManager(Options):
_add_path_to_sys(find_path) _add_path_to_sys(find_path)
mods = [] mods = []
start_time = time.time() start_time = time.time()
logger.info(tr().mod.load.start().format(find_path), tag="load") self.logger.info(tr().mod.load.start().format(find_path), tag="load")
for path in find_path: for path in find_path:
if not path.exists(): if not path.exists():
path.mkdir(parents=True) path.mkdir(parents=True)
@ -166,7 +170,7 @@ class ModManager(Options):
for path in extra_mod_path: for path in extra_mod_path:
if (cache := self.load_mod(path)) is not None: if (cache := self.load_mod(path)) is not None:
mods.append(cache) mods.append(cache)
logger.info(tr().mod.load.use_time().format(time.time() - start_time), tag="load") self.logger.info(tr().mod.load.use_time().format(time.time() - start_time), tag="load")
return mods return mods
def init_mods(self, mods: List[type(ModInfo)]): def init_mods(self, mods: List[type(ModInfo)]):
@ -180,16 +184,16 @@ class ModManager(Options):
try: try:
init_mod = mod_class() init_mod = mod_class()
self.loaded_mod_modules[init_mod.mod_id] = init_mod self.loaded_mod_modules[init_mod.mod_id] = init_mod
logger.info( self.logger.info(
tr().mod.init.success().format(init_mod, init_mod.version), tag="init" tr().mod.init.success().format(init_mod, init_mod.version), tag="init"
) )
except Exception as e: except Exception as e:
logger.error( self.logger.error(
tr().mod.init.faild().format(mod_class, e, traceback.format_exc()), tr().mod.init.faild().format(mod_class, e, traceback.format_exc()),
tag="init", tag="init",
) )
continue continue
logger.info(tr().mod.init.use_time().format(time.time() - start_time), tag="init") self.logger.info(tr().mod.init.use_time().format(time.time() - start_time), tag="init")
def unload_mod(self, mod_id: str, game: Game) -> Optional[ModInfo]: def unload_mod(self, mod_id: str, game: Game) -> Optional[ModInfo]:
""" """
@ -202,15 +206,15 @@ class ModManager(Options):
not (mod_class := self.loaded_mod_modules.get(mod_id)) not (mod_class := self.loaded_mod_modules.get(mod_id))
and (mod_class := self.get_mod_module(mod_id)) is None and (mod_class := self.get_mod_module(mod_id)) is None
): ):
logger.warn(tr().mod.unload.faild.not_find().format(mod_id), tag="unload") self.logger.warn(tr().mod.unload.faild.not_find().format(mod_id), tag="unload")
return None return None
try: try:
mod_class.on_unload(game=game) mod_class.on_unload(game=game)
self.loaded_mod_modules.pop(mod_class.mod_id) self.loaded_mod_modules.pop(mod_class.mod_id)
logger.info(tr().mod.unload.success().format(mod_id), tag="unload") self.logger.info(tr().mod.unload.success().format(mod_id), tag="unload")
return mod_class return mod_class
except Exception as e: except Exception as e:
logger.error( self.logger.error(
tr().mod.unload.faild.error().format(mod_id, e, traceback.format_exc()), tr().mod.unload.faild.error().format(mod_id, e, traceback.format_exc()),
tag="unload", tag="unload",
) )
@ -228,7 +232,7 @@ class ModManager(Options):
return return
mod_class: Optional[ModInfo] = None mod_class: Optional[ModInfo] = None
if unload.mod_id not in self.find_mod_paths: if unload.mod_id not in self.find_mod_paths:
logger.warn( self.logger.warn(
tr().mod.reload.faild.not_find().format(unload.mod_id), tag="reload" tr().mod.reload.faild.not_find().format(unload.mod_id), tag="reload"
) )
paths = self.find_mods_in_path() paths = self.find_mods_in_path()
@ -243,4 +247,4 @@ class ModManager(Options):
self.init_mods([mod_class]) self.init_mods([mod_class])
if mod_id in self.loaded_mod_modules and mod_class is not None: if mod_id in self.loaded_mod_modules and mod_class is not None:
self.loaded_mod_modules[mod_id].on_load(game=game, old_self=mod_class) self.loaded_mod_modules[mod_id].on_load(game=game, old_self=mod_class)
logger.info(tr().mod.reload.success().format(mod_id), tag="reload") self.logger.info(tr().mod.reload.success().format(mod_id), tag="reload")

View File

@ -28,7 +28,7 @@ class Server:
def __init__(self, net_mode="local"): def __init__(self, net_mode="local"):
start_time = time.time() start_time = time.time()
# logging # logging
self.logger = loggers.config.get_logger("server") self.logger = loggers.config.get_logger("server").set_tag("server")
self.logger.info(tr().server.setup.start()) self.logger.info(tr().server.setup.start())
# value # value
self.process_id = os.getpid() self.process_id = os.getpid()

@ -1 +1 @@
Subproject commit a22749deb86a90be84abfab95b670d7623a05668 Subproject commit 7f09f336ef96ce67aeaae30d718404474b65f337