日志修改

This commit is contained in:
even 2025-05-26 19:55:33 +08:00
parent 54377af6df
commit e16d90d3c4
2 changed files with 4 additions and 5 deletions

View File

@ -25,11 +25,11 @@ public class MemoryLogManager implements LoggerManager {
/** /**
* 第一级 是taskId可能同一个账号IP建立多个连接所以保存为list * 第一级 是taskId可能同一个账号IP建立多个连接所以保存为list
* */ * */
private final static Map<String, List<SseEmitter>> taskIdSSEMap = new ConcurrentHashMap<>(); private final Map<String, List<SseEmitter>> taskIdSSEMap = new ConcurrentHashMap<>();
private final static Map<String,StringBuffer> taskIdMemoryLogMap = new ConcurrentHashMap<>(); private final Map<String,StringBuffer> taskIdMemoryLogMap = new ConcurrentHashMap<>();
public static final Integer FLUSH_DB_SIZE=2*1024*1024; public final Integer FLUSH_DB_SIZE=2*1024*1024;
/** /**
* 缓存最近一次执行的日志key是taskIdval是数据库id已入库的情况下用于buffer满了增加日志内容 * 缓存最近一次执行的日志key是taskIdval是数据库id已入库的情况下用于buffer满了增加日志内容
* 读取日志的时候同时读取数据库和内存中的日志 * 读取日志的时候同时读取数据库和内存中的日志
@ -59,7 +59,7 @@ public class MemoryLogManager implements LoggerManager {
* 内存满4mb入库查询日志和入库操作用同一把锁 * 内存满4mb入库查询日志和入库操作用同一把锁
* 然后新内容推sse * 然后新内容推sse
* */ * */
StringBuffer logCache = taskIdMemoryLogMap.getOrDefault(taskId, new StringBuffer()); StringBuffer logCache = taskIdMemoryLogMap.computeIfAbsent(taskId, k -> new StringBuffer());
int length = logCache.length(); int length = logCache.length();
if (length>=FLUSH_DB_SIZE) { if (length>=FLUSH_DB_SIZE) {
synchronized (this){ synchronized (this){

View File

@ -124,7 +124,6 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
@Override @Override
public CommonResult<String> getLogContentByTaskId(String taskId) { public CommonResult<String> getLogContentByTaskId(String taskId) {
return CommonResult.success(loggerManager.getLogContent(taskId)); return CommonResult.success(loggerManager.getLogContent(taskId));
} }
} }