|
@@ -7,7 +7,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.text.MessageFormat;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description RedisLogService
|
|
* @Description RedisLogService
|
|
@@ -23,30 +24,39 @@ public class RedisLogService implements IRedisLogService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String getLogInfo(String taskId) {
|
|
public String getLogInfo(String taskId) {
|
|
- String sss = redisCache.getCacheObject(taskId);
|
|
|
|
- log.error(sss);
|
|
|
|
- return sss;
|
|
|
|
|
|
+ List<String> logs = redisCache.getCacheList(taskId);
|
|
|
|
+ String logStr = logs.get(0);
|
|
|
|
+ log.error(logStr);
|
|
|
|
+ logs.remove(0);
|
|
|
|
+ return logStr;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void info(String taskId, String megStr) {
|
|
public void info(String taskId, String megStr) {
|
|
- this.addInfo("INFO" , taskId, megStr);
|
|
|
|
|
|
+ this.addInfo("INFO", taskId, megStr);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void error(String taskId, String megStr) {
|
|
public void error(String taskId, String megStr) {
|
|
- this.addInfo("ERROR" , taskId, megStr);
|
|
|
|
|
|
+ this.addInfo("ERROR", taskId, megStr);
|
|
}
|
|
}
|
|
|
|
|
|
private void addInfo(String level, String taskId, String megStr) {
|
|
private void addInfo(String level, String taskId, String megStr) {
|
|
- String message = String.format("<p style='color: #58e072'> %s: [%s] -> %s </p>", level, DateUtil.now(), megStr );
|
|
|
|
- if ("ERROR".equals(level)) {
|
|
|
|
- message = String.format("<p style='color: #e3270e'> %s: [%s] %s </p>", level, DateUtil.now(), megStr );
|
|
|
|
|
|
+ List<String> logs = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1000);// 单位:毫秒
|
|
|
|
+ String message = String.format("<p style='color: #58e072'> %s: [%s] -> %s </p>", level, DateUtil.now(), megStr);
|
|
|
|
+ if ("ERROR".equals(level)) {
|
|
|
|
+ message = String.format("<p style='color: #e3270e'> %s: [%s] %s </p>", level, DateUtil.now(), megStr);
|
|
|
|
+ }
|
|
|
|
+ log.info(megStr);
|
|
|
|
+ if (redisCache.hasKey(taskId)) {
|
|
|
|
+ message = redisCache.getCacheObject(taskId) + message;
|
|
|
|
+ }
|
|
|
|
+ logs.add(message);
|
|
|
|
+ redisCache.setCacheList(taskId, logs);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
}
|
|
}
|
|
- log.info(megStr);
|
|
|
|
- if(redisCache.hasKey(taskId)) {
|
|
|
|
- message = redisCache.getCacheObject(taskId) + message;
|
|
|
|
- }
|
|
|
|
- redisCache.setCacheObject(taskId, message);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|