代码提交

This commit is contained in:
2025-07-18 09:32:46 +08:00
parent d6383ac74d
commit 515fb83408
4 changed files with 33 additions and 20 deletions

View File

@@ -1,7 +1,9 @@
package cn.somkit.fmt.action; package cn.somkit.fmt.action;
import cn.metona.cache.Cache;
import cn.somkit.fmt.entity.LoggerMessage; import cn.somkit.fmt.entity.LoggerMessage;
import cn.somkit.fmt.utils.LoggerQueue; import cn.somkit.fmt.utils.LoggerQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@@ -19,8 +21,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
@RequestMapping("/logging") @RequestMapping("/logging")
public class LoggingAction { public class LoggingAction {
@Autowired
private Cache<String, Object> cache;
@GetMapping("/index") @GetMapping("/index")
public String index() throws Exception{ public String index() throws Exception{
return "logging"; return "logging";
} }
@ResponseBody
@PostMapping("/close")
public void close(Boolean closed) throws Exception {
cache.put("closed", closed);
}
} }

View File

@@ -5,11 +5,8 @@
<!-- 日志输出到控制台 --> <!-- 日志输出到控制台 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<filter class="cn.somkit.fmt.filter.LogStashFilter"> <filter class="cn.somkit.fmt.filter.LogStashFilter">
<level>DEBUG</level> <level>INFO</level>
</filter> </filter>
<encoder> <encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern> <pattern>${CONSOLE_LOG_PATTERN}</pattern>
@@ -18,7 +15,7 @@
</appender> </appender>
<!-- 指定日志输出级别以及启动的Appender --> <!-- 指定日志输出级别以及启动的Appender -->
<root level="DEBUG"> <root level="INFO">
<appender-ref ref="CONSOLE"/> <appender-ref ref="CONSOLE"/>
</root> </root>
</configuration> </configuration>

View File

@@ -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.cfg.levels.includes(level)) level = 'info';
if (this.isPaused) return; 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()}); this.logs.push({message, level, ts, id: Date.now() + Math.random()});
if (this.logs.length > this.cfg.maxLines) this.logs.shift(); if (this.logs.length > this.cfg.maxLines) this.logs.shift();
@@ -433,27 +433,27 @@ class LogMonitorAdaptive {
} }
/* 快捷方法 */ /* 快捷方法 */
info(msg) { info(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'info'); this.log(msg, 'info', ts);
} }
warn(msg) { warn(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'warn'); this.log(msg, 'warn', ts);
} }
error(msg) { error(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'error'); this.log(msg, 'error', ts);
} }
success(msg) { success(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'success'); this.log(msg, 'success', ts);
} }
debug(msg) { debug(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'debug'); this.log(msg, 'debug', ts);
} }
system(msg) { system(msg, ts = this.formatTime(new Date())) {
this.log(msg, 'system'); this.log(msg, 'system', ts);
} }
} }

View File

@@ -36,7 +36,12 @@
showLevel: true, // 是否显示日志级别标签 showLevel: true, // 是否显示日志级别标签
//暂停/继续 回调函数 //暂停/继续 回调函数
onTogglePause: (isPaused) => { 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: () => { onCreated: () => {
console.log('日志容器已创建'); console.log('日志容器已创建');