diff options
| -rw-r--r-- | config/config.go | 9 | ||||
| -rw-r--r-- | logger/logger.go | 12 | ||||
| -rw-r--r-- | main.go | 2 | ||||
| -rw-r--r-- | web/controller/index.go | 6 | ||||
| -rw-r--r-- | web/controller/server.go | 3 | ||||
| -rw-r--r-- | web/html/login.html | 2 | ||||
| -rw-r--r-- | web/html/xui/index.html | 23 | ||||
| -rw-r--r-- | web/html/xui/settings.html | 4 | ||||
| -rw-r--r-- | web/job/check_client_ip_job.go | 2 | ||||
| -rw-r--r-- | web/service/server.go | 7 |
10 files changed, 50 insertions, 20 deletions
diff --git a/config/config.go b/config/config.go index e3fe1709..30f0ca81 100644 --- a/config/config.go +++ b/config/config.go @@ -16,10 +16,11 @@ var name string type LogLevel string const ( - Debug LogLevel = "debug" - Info LogLevel = "info" - Warn LogLevel = "warn" - Error LogLevel = "error" + Debug LogLevel = "debug" + Info LogLevel = "info" + Notice LogLevel = "notice" + Warn LogLevel = "warn" + Error LogLevel = "error" ) func GetVersion() string { diff --git a/logger/logger.go b/logger/logger.go index f5b0a878..6e49c850 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -84,3 +84,15 @@ func Errorf(format string, args ...interface{}) { logger.Errorf(format, args...) } } + +func Notice(args ...interface{}) { + if logger != nil { + logger.Notice(args...) + } +} + +func Noticef(format string, args ...interface{}) { + if logger != nil { + logger.Noticef(format, args...) + } +} @@ -27,6 +27,8 @@ func runWebServer() { logger.InitLogger(logging.DEBUG) case config.Info: logger.InitLogger(logging.INFO) + case config.Notice: + logger.InitLogger(logging.NOTICE) case config.Warn: logger.InitLogger(logging.WARNING) case config.Error: diff --git a/web/controller/index.go b/web/controller/index.go index 0254106c..9be88273 100644 --- a/web/controller/index.go +++ b/web/controller/index.go @@ -64,7 +64,7 @@ func (a *IndexController) login(c *gin.Context) { user := a.userService.CheckUser(form.Username, form.Password, form.LoginSecret) timeStr := time.Now().Format("2006-01-02 15:04:05") if user == nil { - logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password) + logger.Warningf("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password) a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0) pureJsonMsg(c, false, I18nWeb(c, "pages.login.toasts.wrongUsernameOrPassword")) return @@ -75,13 +75,13 @@ func (a *IndexController) login(c *gin.Context) { sessionMaxAge, err := a.settingService.GetSessionMaxAge() if err != nil { - logger.Infof("Unable to get session's max age from DB") + logger.Warningf("Unable to get session's max age from DB") } if sessionMaxAge > 0 { err = session.SetMaxAge(c, sessionMaxAge*60) if err != nil { - logger.Infof("Unable to set session's max age") + logger.Warningf("Unable to set session's max age") } } diff --git a/web/controller/server.go b/web/controller/server.go index cc4eaacc..086d9ec9 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -118,7 +118,8 @@ func (a *ServerController) restartXrayService(c *gin.Context) { func (a *ServerController) getLogs(c *gin.Context) { count := c.Param("count") - logs, err := a.serverService.GetLogs(count) + logLevel := c.PostForm("logLevel") + logs, err := a.serverService.GetLogs(count, logLevel) if err != nil { jsonMsg(c, "getLogs", err) return diff --git a/web/html/login.html b/web/html/login.html index 3ec410c6..61381a61 100644 --- a/web/html/login.html +++ b/web/html/login.html @@ -87,7 +87,7 @@ <a-col :span="12"> <a-select ref="selectLang" v-model="lang" @change="setLang(lang)" :dropdown-class-name="themeSwitcher.darkCardClass"> <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs"> - <span role="img" aria-label="l.name" v-text="l.icon"></span> + <span role="img" :aria-label="l.name" v-text="l.icon"></span> <span v-text="l.name"></span> </a-select-option> </a-select> diff --git a/web/html/xui/index.html b/web/html/xui/index.html index 989aa286..236ab010 100644 --- a/web/html/xui/index.html +++ b/web/html/xui/index.html @@ -86,7 +86,7 @@ <a-col :sm="24" :md="12"> <a-card hoverable :class="themeSwitcher.darkCardClass"> {{ i18n "menu.link" }}: - <a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">{{ i18n "pages.index.logs" }}</a-tag> + <a-tag color="blue" style="cursor: pointer;" @click="openLogs(logModal.rows, logModal.logLevel)">{{ i18n "pages.index.logs" }}</a-tag> <a-tag color="blue" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag> <a-tag color="blue" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag> </a-card> @@ -253,7 +253,7 @@ <a-form-item label="Count"> <a-select v-model="logModal.rows" style="width: 80px" - @change="openLogs(logModal.rows)" + @change="openLogs(logModal.rows, logModal.logLevel)" :dropdown-class-name="themeSwitcher.darkCardClass"> <a-select-option value="10">10</a-select-option> <a-select-option value="20">20</a-select-option> @@ -261,8 +261,20 @@ <a-select-option value="100">100</a-select-option> </a-select> </a-form-item> + <a-form-item label="Log Level"> + <a-select v-model="logModal.logLevel" + style="width: 120px" + @change="openLogs(logModal.rows, logModal.logLevel)" + :dropdown-class-name="themeSwitcher.darkCardClass"> + <a-select-option value="debug">Debug</a-select-option> + <a-select-option value="info">Info</a-select-option> + <a-select-option value="notice">Notice</a-select-option> + <a-select-option value="warning">Warning</a-select-option> + <a-select-option value="err">Error</a-select-option> + </a-select> + </a-form-item> <a-form-item> - <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows)"><a-icon type="sync"></a-icon> Reload</button> + <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows, logModal.logLevel)"><a-icon type="sync"></a-icon> Reload</button> </a-form-item> <a-form-item> <a-button type="primary" style="margin-bottom: 10px;" @@ -397,6 +409,7 @@ visible: false, logs: '', rows: 20, + logLevel: 'info', show(logs, rows) { this.visible = true; this.rows = rows; @@ -501,9 +514,9 @@ return; } }, - async openLogs(rows) { + async openLogs(rows, logLevel) { this.loading(true); - const msg = await HttpUtil.post('server/logs/' + rows); + const msg = await HttpUtil.post('server/logs/' + rows, { logLevel: `${logLevel}` }); this.loading(false); if (!msg.success) { return; diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html index 745959a2..abcacada 100644 --- a/web/html/xui/settings.html +++ b/web/html/xui/settings.html @@ -116,7 +116,7 @@ style="width: 100%" > <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs"> - <span role="img" aria-label="l.name" v-text="l.icon"></span> + <span role="img" :aria-label="l.name" v-text="l.icon"></span> <span v-text="l.name"></span> </a-select-option> </a-select> @@ -386,7 +386,7 @@ style="width: 100%" > <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs"> - <span role="img" aria-label="l.name" v-text="l.icon"></span> + <span role="img" :aria-label="l.name" v-text="l.icon"></span> <span v-text="l.name"></span> </a-select-option> </a-select> diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go index 348f9b9d..c1b4ab34 100644 --- a/web/job/check_client_ip_job.go +++ b/web/job/check_client_ip_job.go @@ -242,7 +242,7 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai disAllowedIps = append(disAllowedIps, ips[limitIp:]...) for i := limitIp; i < len(ips); i++ { - logger.Info("[LIMIT_IP] Email=", clientEmail, " SRC=", ips[i]) + logger.Notice("[LIMIT_IP] Email=", clientEmail, " SRC=", ips[i]) } } } diff --git a/web/service/server.go b/web/service/server.go index d5f7adc1..936e6469 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -380,16 +380,17 @@ func (s *ServerService) UpdateXray(version string) error { } -func (s *ServerService) GetLogs(count string) ([]string, error) { - // Define the journalctl command and its arguments +func (s *ServerService) GetLogs(count string, logLevel string) ([]string, error) { var cmdArgs []string if runtime.GOOS == "linux" { cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", count} + if logLevel != "" { + cmdArgs = append(cmdArgs, "-p", logLevel) + } } else { return []string{"Unsupported operating system"}, nil } - // Run the command cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) var out bytes.Buffer cmd.Stdout = &out |
