From 515fb83408beca845b361d53020fbdc6488aa17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=AB=E5=BD=B1233?= <1440196015@qq.com> Date: Fri, 18 Jul 2025 09:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/somkit/fmt/action/LoggingAction.java | 11 ++++++++ src/main/resources/logback-spring.xml | 7 ++--- .../static/common/js/LogMonitorAdaptive.js | 28 +++++++++---------- src/main/resources/templates/logging.html | 7 ++++- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/cn/somkit/fmt/action/LoggingAction.java b/src/main/java/cn/somkit/fmt/action/LoggingAction.java index 5e6d454..bea8a45 100644 --- a/src/main/java/cn/somkit/fmt/action/LoggingAction.java +++ b/src/main/java/cn/somkit/fmt/action/LoggingAction.java @@ -1,7 +1,9 @@ package cn.somkit.fmt.action; +import cn.metona.cache.Cache; import cn.somkit.fmt.entity.LoggerMessage; import cn.somkit.fmt.utils.LoggerQueue; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -19,8 +21,17 @@ import java.util.concurrent.atomic.AtomicBoolean; @RequestMapping("/logging") public class LoggingAction { + @Autowired + private Cache cache; + @GetMapping("/index") public String index() throws Exception{ return "logging"; } + + @ResponseBody + @PostMapping("/close") + public void close(Boolean closed) throws Exception { + cache.put("closed", closed); + } } diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index eb7e062..477245a 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -5,11 +5,8 @@ - - DEBUG - - DEBUG + INFO ${CONSOLE_LOG_PATTERN} @@ -18,7 +15,7 @@ - + diff --git a/src/main/resources/static/common/js/LogMonitorAdaptive.js b/src/main/resources/static/common/js/LogMonitorAdaptive.js index c5e9ee3..b6f279a 100644 --- a/src/main/resources/static/common/js/LogMonitorAdaptive.js +++ b/src/main/resources/static/common/js/LogMonitorAdaptive.js @@ -269,11 +269,11 @@ class LogMonitorAdaptive { } /* ------------------------ 日志渲染 ------------------------ */ - log(message, level = 'info') { + log(message, level = 'info', ts = this.formatTime(new Date())) { if (!this.cfg.levels.includes(level)) level = 'info'; if (this.isPaused) return; - const ts = this.cfg.showTimestamp ? this.formatTime(new Date()) : ''; + ts = this.cfg.showTimestamp ? ts : ''; this.logs.push({message, level, ts, id: Date.now() + Math.random()}); if (this.logs.length > this.cfg.maxLines) this.logs.shift(); @@ -433,27 +433,27 @@ class LogMonitorAdaptive { } /* 快捷方法 */ - info(msg) { - this.log(msg, 'info'); + info(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'info', ts); } - warn(msg) { - this.log(msg, 'warn'); + warn(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'warn', ts); } - error(msg) { - this.log(msg, 'error'); + error(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'error', ts); } - success(msg) { - this.log(msg, 'success'); + success(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'success', ts); } - debug(msg) { - this.log(msg, 'debug'); + debug(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'debug', ts); } - system(msg) { - this.log(msg, 'system'); + system(msg, ts = this.formatTime(new Date())) { + this.log(msg, 'system', ts); } } \ No newline at end of file diff --git a/src/main/resources/templates/logging.html b/src/main/resources/templates/logging.html index 1c07d39..50fe9fb 100644 --- a/src/main/resources/templates/logging.html +++ b/src/main/resources/templates/logging.html @@ -36,7 +36,12 @@ showLevel: true, // 是否显示日志级别标签 //暂停/继续 回调函数 onTogglePause: (isPaused) => { - console.log(isPaused ? '暂停' : '继续'); + const options = { + url: Fmt.ctx() + '/logging/close', + data: {closed: isPaused}, + method: 'post' + }; + Fmt.axios(options).then((result) => console.log(result)).catch((err) => console.error(err)); }, onCreated: () => { console.log('日志容器已创建');