代码提交
This commit is contained in:
@@ -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<String, Object> cache;
|
||||
|
||||
@GetMapping("/index")
|
||||
public String index() throws Exception{
|
||||
return "logging";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/close")
|
||||
public void close(Boolean closed) throws Exception {
|
||||
cache.put("closed", closed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
|
||||
<!-- 日志输出到控制台 -->
|
||||
<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">
|
||||
<level>DEBUG</level>
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
@@ -18,7 +15,7 @@
|
||||
</appender>
|
||||
|
||||
<!-- 指定日志输出级别,以及启动的Appender -->
|
||||
<root level="DEBUG">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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('日志容器已创建');
|
||||
|
||||
Reference in New Issue
Block a user