Add an option to filter logs by level (#427)

This commit is contained in:
角砂糖
2025-06-26 19:55:07 +08:00
committed by GitHub
parent 23ee79fe9d
commit 5ebb554e54
3 changed files with 59 additions and 15 deletions

View File

@@ -399,7 +399,12 @@
"Reverse": "反转", "Reverse": "反转",
"Delete Chapters": "删除章节", "Delete Chapters": "删除章节",
"Path copied to clipboard": "路径已复制到剪贴板", "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": { "zh_TW": {
"Home": "首頁", "Home": "首頁",
@@ -801,6 +806,11 @@
"Reverse": "反轉", "Reverse": "反轉",
"Delete Chapters": "刪除章節", "Delete Chapters": "刪除章節",
"Path copied to clipboard": "路徑已複製到剪貼簿", "Path copied to clipboard": "路徑已複製到剪貼簿",
"Reverse default chapter order": "反轉預設章節順序" "Reverse default chapter order": "反轉預設章節順序",
"Reload Configs": "重新載入設定檔",
"Reload": "重載",
"Disable Length Limitation": "禁用長度限制",
"Only valid for this run": "僅對本次運行有效",
"Logs": "日誌"
} }
} }

View File

@@ -193,12 +193,46 @@ class LogsPage extends StatefulWidget {
} }
class _LogsPageState extends State<LogsPage> { class _LogsPageState extends State<LogsPage> {
String logLevelToShow = "all";
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var logToShow = logLevelToShow == "all"
? Log.logs
: Log.logs.where((log) => log.level.name == logLevelToShow).toList();
return Scaffold( return Scaffold(
appBar: Appbar( appBar: Appbar(
title: const Text("Logs"), title: Text("Logs".tl),
actions: [ 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( IconButton(
onPressed: () => setState(() { onPressed: () => setState(() {
final RelativeRect position = RelativeRect.fromLTRB( final RelativeRect position = RelativeRect.fromLTRB(
@@ -217,7 +251,7 @@ class _LogsPageState extends State<LogsPage> {
onTap: () { onTap: () {
Log.ignoreLimitation = true; Log.ignoreLimitation = true;
context.showMessage( context.showMessage(
message: "Only valid for this run"); message: "Only valid for this run".tl);
}, },
), ),
PopupMenuItem( PopupMenuItem(
@@ -232,9 +266,9 @@ class _LogsPageState extends State<LogsPage> {
body: ListView.builder( body: ListView.builder(
reverse: true, reverse: true,
controller: ScrollController(), controller: ScrollController(),
itemCount: Log.logs.length, itemCount: logToShow.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
index = Log.logs.length - index - 1; index = logToShow.length - index - 1;
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8), padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: SelectionArea( child: SelectionArea(
@@ -253,7 +287,7 @@ class _LogsPageState extends State<LogsPage> {
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1), padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
child: Text(Log.logs[index].title), child: Text(logToShow[index].title),
), ),
), ),
const SizedBox( const SizedBox(
@@ -265,16 +299,16 @@ class _LogsPageState extends State<LogsPage> {
Theme.of(context).colorScheme.error, Theme.of(context).colorScheme.error,
Theme.of(context).colorScheme.errorContainer, Theme.of(context).colorScheme.errorContainer,
Theme.of(context).colorScheme.primaryContainer Theme.of(context).colorScheme.primaryContainer
][Log.logs[index].level.index], ][logToShow[index].level.index],
borderRadius: borderRadius:
const BorderRadius.all(Radius.circular(16)), const BorderRadius.all(Radius.circular(16)),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1), padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
child: Text( child: Text(
Log.logs[index].level.name, logToShow[index].level.name,
style: TextStyle( style: TextStyle(
color: Log.logs[index].level.index == 0 color: logToShow[index].level.index == 0
? Colors.white ? Colors.white
: Colors.black), : Colors.black),
), ),
@@ -282,14 +316,14 @@ class _LogsPageState extends State<LogsPage> {
), ),
], ],
), ),
Text(Log.logs[index].content), Text(logToShow[index].content),
Text(Log.logs[index].time Text(logToShow[index].time
.toString() .toString()
.replaceAll(RegExp(r"\.\w+"), "")), .replaceAll(RegExp(r"\.\w+"), "")),
TextButton( TextButton(
onPressed: () { onPressed: () {
Clipboard.setData( Clipboard.setData(
ClipboardData(text: Log.logs[index].content)); ClipboardData(text: logToShow[index].content));
}, },
child: Text("Copy".tl), child: Text("Copy".tl),
), ),

View File

@@ -18,8 +18,8 @@ class DebugPageState extends State<DebugPage> {
slivers: [ slivers: [
SliverAppbar(title: Text("Debug".tl)), SliverAppbar(title: Text("Debug".tl)),
_CallbackSetting( _CallbackSetting(
title: "Reload Configs", title: "Reload Configs".tl,
actionTitle: "Reload", actionTitle: "Reload".tl,
callback: () { callback: () {
ComicSourceManager().reload(); ComicSourceManager().reload();
}, },