From 17a483266e8db0749dd6889a6dc61a3da3c88516 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sun, 2 Apr 2023 12:13:49 +0200 Subject: [PATCH] [log view] add refresh,count,download #50 --- web/controller/server.go | 5 +++-- web/html/xui/index.html | 43 ++++++++++++++++++++++++++++++---------- web/service/server.go | 4 ++-- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/web/controller/server.go b/web/controller/server.go index 7b7239d5..43a1fadc 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -38,7 +38,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) { g.POST("/stopXrayService", a.stopXrayService) g.POST("/restartXrayService", a.restartXrayService) g.POST("/installXray/:version", a.installXray) - g.POST("/logs", a.getLogs) + g.POST("/logs/:count", a.getLogs) } func (a *ServerController) refreshStatus() { @@ -109,7 +109,8 @@ func (a *ServerController) restartXrayService(c *gin.Context) { } func (a *ServerController) getLogs(c *gin.Context) { - logs, err := a.serverService.GetLogs() + count := c.Param("count") + logs, err := a.serverService.GetLogs(count) if err != nil { jsonMsg(c, I18n(c, "getLogs"), err) return diff --git a/web/html/xui/index.html b/web/html/xui/index.html index 9a0f2cf4..10b01759 100644 --- a/web/html/xui/index.html +++ b/web/html/xui/index.html @@ -93,7 +93,7 @@ x-ui: {{ .cur_ver }} - Logs + Logs {{ i18n "pages.index.operationHours" }}: [[ formatSecond(status.uptime) ]] @@ -194,11 +194,30 @@ :class="siderDrawer.isDarkTheme ? darkClass : ''" width="800px" footer=""> - - - - -
[[ index ]][[ log ]]
+ + + + 10 + 20 + 50 + 100 + + + + + + + + {{ i18n "download" }} x-ui.log + + + + {{template "js" .}} @@ -296,9 +315,11 @@ const logModal = { visible: false, logs: '', - show(logs) { + rows: 20, + show(logs, rows) { this.visible = true; - this.logs = logs; + this.rows = rows; + this.logs = logs.join("\n"); }, hide() { this.visible = false; @@ -372,14 +393,14 @@ return; } }, - async openLogs(){ + async openLogs(rows){ this.loading(true); - const msg = await HttpUtil.post('server/logs'); + const msg = await HttpUtil.post('server/logs/'+rows); this.loading(false); if (!msg.success) { return; } - logModal.show(msg.obj); + logModal.show(msg.obj,rows); } }, async mounted() { diff --git a/web/service/server.go b/web/service/server.go index 44e5a0a6..d3214ab7 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -327,11 +327,11 @@ func (s *ServerService) UpdateXray(version string) error { } -func (s *ServerService) GetLogs() ([]string, error) { +func (s *ServerService) GetLogs(count string) ([]string, error) { // Define the journalctl command and its arguments var cmdArgs []string if runtime.GOOS == "linux" { - cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", "100"} + cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", count} } else { return []string{"Unsupported operating system"}, nil }