-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'错误缓存' | ||
import logging | ||
|
||
|
||
class InMemoryLogHandler(logging.Handler): | ||
"""创建一个内存中的日志处理器 | ||
Args: | ||
logging (_type_): _description_ | ||
""" | ||
|
||
def __init__(self, max_logs=20): | ||
super().__init__() | ||
self.log_buffer = [] | ||
self.max_logs = max_logs | ||
|
||
def emit(self, record): | ||
log_entry = self.format(record) | ||
if len(self.log_buffer) >= self.max_logs: | ||
# 如果日志超过最大限制,删除最旧的日志 | ||
self.log_buffer.pop(0) | ||
self.log_buffer.append(log_entry) | ||
|
||
def get_logs(self): | ||
"""获取日志 | ||
Returns: | ||
str: _description_ | ||
""" | ||
return "\n\n".join(self.log_buffer) | ||
|
||
|
||
# 初始化日志系统 | ||
logger = logging.getLogger("lfy") | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# 设置格式 | ||
formatter = logging.Formatter( | ||
'%(asctime)s - %(levelname)s\n[%(filename)s:%(lineno)d]\n%(message)s') | ||
# 使用自定义内存日志处理器 | ||
in_memory_handler = InMemoryLogHandler(max_logs=10) | ||
in_memory_handler.setFormatter(formatter) | ||
logger.addHandler(in_memory_handler) | ||
|
||
# 测试日志输出 | ||
# for i in range(15): | ||
# logger.info(f"Log message {i}") | ||
|
||
# 打印当前的内存日志 | ||
# print("Current logs:") | ||
# print(in_memory_handler.get_logs()) | ||
|
||
|
||
def get_logger(): | ||
"""提供给外部的接口 | ||
Returns: | ||
_type_: _description_ | ||
""" | ||
return logger | ||
|
||
|
||
def get_log_handler(): | ||
"""获取当前的内存日志 | ||
Returns: | ||
_type_: _description_ | ||
""" | ||
return in_memory_handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
from lfy.api.utils import is_text | ||
from lfy.api.utils.bak import backup_gsettings | ||
from lfy.api.utils.check_update import main as check_update | ||
from lfy.api.utils.debug import get_log_handler | ||
from lfy.preference import PreferenceWindow | ||
from lfy.settings import Settings | ||
from lfy.translate import TranslateWindow | ||
|
@@ -101,7 +102,6 @@ def on_about_action(self, _widget, _w): | |
""" | ||
# pylint: disable=E1101 | ||
path = f'{RES_PATH}/{self._application_id}.metainfo.xml' | ||
print(path) | ||
|
||
ad = Adw.AboutDialog.new_from_appdata(path, VERSION) | ||
ad.set_developers(['yuh <[email protected]>, 2023-2023']) | ||
|
@@ -124,9 +124,12 @@ def on_about_action(self, _widget, _w): | |
if "server-sk-" in k and ("key" not in v or "Key" not in v): | ||
v = "******" | ||
ss[k] = v | ||
s += f"\n\n******* config *******\n" | ||
s += "\n\n******* config *******\n" | ||
s += json.dumps(ss, indent=4, ensure_ascii=False) | ||
s += f"\n************" | ||
s += "\n************" | ||
|
||
s += "\n\n******* debug log *******\n" | ||
s += get_log_handler().get_logs() | ||
|
||
ad.set_debug_info(s) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters