提交 d018f2fa 编写于 作者: O o2null

Merge branch 'feature/viewSystemLog' into 'develop'

Merge of feature/[系统日志]增加日志分级标志 to develop

See merge request o2oa/o2oa!193
......@@ -57,7 +57,7 @@ public class NodeAgent extends Thread {
try (DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream())) {
String json = dis.readUTF();
logger.info("receive socket json={}",json);
//logger.info("receive socket json={}",json);
CommandObject commandObject = XGsonBuilder.instance().fromJson(json, CommandObject.class);
if (BooleanUtils.isTrue(Config.currentNode().nodeAgentEncrypt())) {
String decrypt = Crypto.rsaDecrypt(commandObject.getCredential(), Config.privateKey());
......@@ -143,11 +143,15 @@ public class NodeAgent extends Thread {
curReadSize = curReadSize + bytes.length + 1;
String lineStr = new String(bytes);
String time = curTime;
String logLevel = "";
if (lineStr.length() > 23) {
time = StringUtils.left(lineStr, 19);
if (DateTools.isDateTime(time)) {
time = StringUtils.left(lineStr, 23);
curTime = time;
if(lineStr.length() > 29){
logLevel = StringUtils.right(StringUtils.left(lineStr, 29),5).trim();
}
} else {
if (StringUtils.isEmpty(curTime)) {
time = "2020-01-01 00:00:01.001";
......@@ -164,6 +168,8 @@ public class NodeAgent extends Thread {
}
Map<String, String> map = new HashMap<>();
map.put("logTime",time+"#"+Config.node());
map.put("node", Config.node());
map.put("logLevel", logLevel);
map.put("lineLog", lineStr);
list.add(map);
if (curReadSize > LOG_MAX_READ_SIZE){
......
......@@ -6,10 +6,12 @@ import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Nodes;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpToken;
import com.x.base.core.project.jaxrs.WoValue;
import com.x.base.core.project.jaxrs.WrapStringList;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
......@@ -30,29 +32,29 @@ class ActionGetSystemLog extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionGetSystemLog.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String tag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String tag) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
Wo wo = new Wo();
List<Wo> woList = new ArrayList<>();
String key = effectivePerson.getDistinguishedName();
if(key.indexOf("@") > -1){
key = key.split("@")[1] + tag;
}
if(Config.node().equals(Config.resource_node_centersPirmaryNode())){
wo.setValueList(getSystemLog(key));
woList = getSystemLog(key);
}else{
List<NameValuePair> headers = ListTools.toList(new NameValuePair(HttpToken.X_Token, effectivePerson.getToken()));
wo = ConnectionAction.get(Config.url_x_program_center_jaxrs("warnlog", "view", "system", "log", "tag", tag), headers).getData(Wo.class);
woList = ConnectionAction.get(Config.url_x_program_center_jaxrs("warnlog", "view", "system", "log", "tag", tag), headers).getDataAsList(Wo.class);
}
result.setData(wo);
result.setData(woList);
return result;
}
synchronized private List<String> getSystemLog(String key) throws Exception{
synchronized private List<Wo> getSystemLog(String key) throws Exception{
Nodes nodes = Config.nodes();
List<SystemLog> allLogs = new ArrayList<>();
List<Wo> allLogs = new ArrayList<>();
for (String node : nodes.keySet()){
if(nodes.get(node).getApplication().getEnable() || nodes.get(node).getCenter().getEnable()){
try (Socket socket = new Socket(node, nodes.get(node).nodeAgentPort())) {
......@@ -78,14 +80,13 @@ class ActionGetSystemLog extends BaseAction {
dos.writeLong(lastPoint);
dos.flush();
logger.info("socket dispatch getSystemLog to {}:{} lastPoint={}", node, nodes.get(node).nodeAgentPort(), lastPoint);
//logger.debug("socket dispatch getSystemLog to {}:{} lastPoint={}", node, nodes.get(node).nodeAgentPort(), lastPoint);
String result = dis.readUTF();
if(StringUtils.isNotEmpty(result) && result.startsWith("[")){
List<SystemLog> list = gson.fromJson(result, new TypeToken<List<SystemLog>>(){}.getType());
List<Wo> list = gson.fromJson(result, new TypeToken<List<Wo>>(){}.getType());
allLogs.addAll(list);
long returnLastPoint = dis.readLong();
logger.info("用户的cacheKey={},最后日志标志:{}", cacheKey, returnLastPoint);
if(clo==null){
clo = new CacheLogObject();
clo.setUserToken(key);
......@@ -103,24 +104,21 @@ class ActionGetSystemLog extends BaseAction {
}
}
}
List<String> list = new ArrayList<>();
allLogs.stream().sorted((o1, o2) -> {
return o1.logTime.compareTo(o2.logTime);
}).forEach(o -> {
list.add(o.getLineLog());
});
return list;
return allLogs;
}
public static class Wo extends WrapStringList {
}
public static class SystemLog {
public static class Wo extends GsonPropertyObject {
private String logTime;
private String lineLog;
private String node;
private String logLevel;
public String getLogTime() {
return logTime;
}
......@@ -136,6 +134,22 @@ class ActionGetSystemLog extends BaseAction {
public void setLineLog(String lineLog) {
this.lineLog = lineLog;
}
public String getNode() {
return node;
}
public void setNode(String node) {
this.node = node;
}
public String getLogLevel() {
return logLevel;
}
public void setLogLevel(String logLevel) {
this.logLevel = logLevel;
}
}
}
......@@ -148,7 +148,7 @@ public class WarnLogAction extends StandardJaxrsAction {
public void getSystemLog(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("日志标识") @PathParam("tag") String tag) {
EffectivePerson effectivePerson = this.effectivePerson(request);
ActionResult<ActionGetSystemLog.Wo> result = new ActionResult<>();
ActionResult<List<ActionGetSystemLog.Wo>> result = new ActionResult<>();
try {
result = new ActionGetSystemLog().execute(effectivePerson, tag);
} catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册