From 5ebb554e54b8336b45e5ebd65573ee6df28f0cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=92=E7=A0=82=E7=B3=96?= <90336521+lings03@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:55:07 +0800 Subject: [PATCH] Add an option to filter logs by level (#427) --- assets/translation.json | 14 +++++++-- lib/pages/settings/app.dart | 56 ++++++++++++++++++++++++++++------- lib/pages/settings/debug.dart | 4 +-- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/assets/translation.json b/assets/translation.json index 4fbd451..f8b058e 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -399,7 +399,12 @@ "Reverse": "反转", "Delete Chapters": "删除章节", "Path copied to clipboard": "路径已复制到剪贴板", - "Reverse default chapter order": "反转默认章节顺序" + "Reverse default chapter order": "反转默认章节顺序", + "Reload Configs": "重新加载配置文件", + "Reload": "重载", + "Disable Length Limitation": "禁用长度限制", + "Only valid for this run": "仅对本次运行有效", + "Logs": "日志" }, "zh_TW": { "Home": "首頁", @@ -801,6 +806,11 @@ "Reverse": "反轉", "Delete Chapters": "刪除章節", "Path copied to clipboard": "路徑已複製到剪貼簿", - "Reverse default chapter order": "反轉預設章節順序" + "Reverse default chapter order": "反轉預設章節順序", + "Reload Configs": "重新載入設定檔", + "Reload": "重載", + "Disable Length Limitation": "禁用長度限制", + "Only valid for this run": "僅對本次運行有效", + "Logs": "日誌" } } \ No newline at end of file diff --git a/lib/pages/settings/app.dart b/lib/pages/settings/app.dart index a6f91f8..c057eb3 100644 --- a/lib/pages/settings/app.dart +++ b/lib/pages/settings/app.dart @@ -193,12 +193,46 @@ class LogsPage extends StatefulWidget { } class _LogsPageState extends State { + String logLevelToShow = "all"; + @override Widget build(BuildContext context) { + var logToShow = logLevelToShow == "all" + ? Log.logs + : Log.logs.where((log) => log.level.name == logLevelToShow).toList(); return Scaffold( appBar: Appbar( - title: const Text("Logs"), + title: Text("Logs".tl), actions: [ + IconButton( + onPressed: () => setState(() { + final RelativeRect position = RelativeRect.fromLTRB( + MediaQuery.of(context).size.width, + MediaQuery.of(context).padding.top + kToolbarHeight, + 0.0, + 0.0, + ); + showMenu(context: context, position: position, items: [ + PopupMenuItem( + child: Text("all"), + onTap: () => setState(() => logLevelToShow = "all") + ), + PopupMenuItem( + child: Text("info"), + onTap: () => setState(() => logLevelToShow = "info") + ), + PopupMenuItem( + child: Text("warning"), + onTap: () => setState(() => logLevelToShow = "warning") + ), + PopupMenuItem( + child: Text("error"), + onTap: () => setState(() => logLevelToShow = "error") + ), + ]); + }), + icon: const Icon(Icons.filter_list_outlined) + ), IconButton( onPressed: () => setState(() { final RelativeRect position = RelativeRect.fromLTRB( @@ -217,7 +251,7 @@ class _LogsPageState extends State { onTap: () { Log.ignoreLimitation = true; context.showMessage( - message: "Only valid for this run"); + message: "Only valid for this run".tl); }, ), PopupMenuItem( @@ -232,9 +266,9 @@ class _LogsPageState extends State { body: ListView.builder( reverse: true, controller: ScrollController(), - itemCount: Log.logs.length, + itemCount: logToShow.length, itemBuilder: (context, index) { - index = Log.logs.length - index - 1; + index = logToShow.length - index - 1; return Padding( padding: const EdgeInsets.fromLTRB(16, 0, 16, 8), child: SelectionArea( @@ -253,7 +287,7 @@ class _LogsPageState extends State { ), child: Padding( padding: const EdgeInsets.fromLTRB(5, 0, 5, 1), - child: Text(Log.logs[index].title), + child: Text(logToShow[index].title), ), ), const SizedBox( @@ -265,16 +299,16 @@ class _LogsPageState extends State { Theme.of(context).colorScheme.error, Theme.of(context).colorScheme.errorContainer, Theme.of(context).colorScheme.primaryContainer - ][Log.logs[index].level.index], + ][logToShow[index].level.index], borderRadius: const BorderRadius.all(Radius.circular(16)), ), child: Padding( padding: const EdgeInsets.fromLTRB(5, 0, 5, 1), child: Text( - Log.logs[index].level.name, + logToShow[index].level.name, style: TextStyle( - color: Log.logs[index].level.index == 0 + color: logToShow[index].level.index == 0 ? Colors.white : Colors.black), ), @@ -282,14 +316,14 @@ class _LogsPageState extends State { ), ], ), - Text(Log.logs[index].content), - Text(Log.logs[index].time + Text(logToShow[index].content), + Text(logToShow[index].time .toString() .replaceAll(RegExp(r"\.\w+"), "")), TextButton( onPressed: () { Clipboard.setData( - ClipboardData(text: Log.logs[index].content)); + ClipboardData(text: logToShow[index].content)); }, child: Text("Copy".tl), ), diff --git a/lib/pages/settings/debug.dart b/lib/pages/settings/debug.dart index 232861b..e5889fd 100644 --- a/lib/pages/settings/debug.dart +++ b/lib/pages/settings/debug.dart @@ -18,8 +18,8 @@ class DebugPageState extends State { slivers: [ SliverAppbar(title: Text("Debug".tl)), _CallbackSetting( - title: "Reload Configs", - actionTitle: "Reload", + title: "Reload Configs".tl, + actionTitle: "Reload".tl, callback: () { ComicSourceManager().reload(); },