refactor: optimize logs

This commit is contained in:
Frank.R.Wu 2021-12-09 14:43:11 +08:00
parent 0e85394612
commit 4a589474b4
3 changed files with 14 additions and 15 deletions

View File

@ -21,12 +21,12 @@ import java.util.Map;
import java.util.TimerTask;
public class AliveCheckClientAction {
private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class);
protected boolean waitForSetNode = false;
public static final int sendDelay = 2000;
public static final int checkDelay = 5000;
private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class);
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss");
private final String masterPubkey;
protected boolean waitForSetNode = false;
TimerTask sendPingTask;
TimerTask checkAliveTask;
private long lastMasterPongTime = System.currentTimeMillis();
@ -66,7 +66,7 @@ public class AliveCheckClientAction {
LOGGER.debug(
String.format(
"f %s",
new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss")
DATE_FORMAT
.format(System.currentTimeMillis())));
Map<String, String> ping = new HashMap<>();
ping.put("action", "masterPing");
@ -93,10 +93,9 @@ public class AliveCheckClientAction {
long cur = System.currentTimeMillis();
if (cur - lastMasterPongTime >= (2 * sendDelay)) {
LOGGER.info(
"lastMasterPongTime="
+ new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss")
.format(lastMasterPongTime)
+ " 认为master崩溃!");
"master maybe crash down, because lastMasterPongTime="
+ DATE_FORMAT.format(lastMasterPongTime)
+ "!");
// 向NC发通知重新选举master如果NC没有收到所有节点的重选请求就认为是这个节点和master连接断开
// 这个节点需要重连master
@ -107,9 +106,9 @@ public class AliveCheckClientAction {
for (MultiContractMeta meta : CMActions.manager.multiContractRecorder.getStatus().values()) {
if (meta.getMasterNode().equals(masterPubkey)) {
LOGGER.info(
"认为合约 "
"master of contract "
+ meta.getContractID()
+ " 的master崩溃 master="
+ " maybe crash down! master="
+ masterPubkey);
request.put("contractID", meta.getContractID());
int lastSeq = meta.getLastExeSeq();
@ -130,8 +129,7 @@ public class AliveCheckClientAction {
};
lastMasterPongTime = System.currentTimeMillis();
LOGGER.info(
"设置 lastMasterPongTime="
+ new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(lastMasterPongTime));
"lastMasterPongTime=" + DATE_FORMAT.format(lastMasterPongTime));
HeartBeatUtil.getInstance().schedule(sendPingTask, sendDelay / 2, checkDelay);
HeartBeatUtil.getInstance().schedule(checkAliveTask, sendDelay, checkDelay);
}

View File

@ -324,7 +324,7 @@ public class NodeCenterClientController implements NodeCenterConn {
@Action(async = true)
public void onQueryNodeAddress(JsonObject jo, ResultCallback cb) {
LOGGER.info("onQueryNodeAddress:" + jo.toString());
LOGGER.debug("onQueryNodeAddress:" + jo.toString());
sync.wakeUp(jo.get("responseID").getAsString(), jo.toString());
}
@ -349,7 +349,8 @@ public class NodeCenterClientController implements NodeCenterConn {
sendMsg(JsonUtil.toJson(req));
//TODO use async instead?
ContractResult cr = sync.syncSleep(requestID);
LOGGER.info("connectToNode result:" + JsonUtil.toJson(cr));
LOGGER.debug("result: " + JsonUtil.toJson(cr));
LOGGER.info("node " + pubKey + " succeed!");
if (!cr.result.equals(JsonNull.INSTANCE)) {
try {
JsonObject jo = cr.result.getAsJsonObject();

View File

@ -70,7 +70,7 @@ public class AgentManager implements AgentPeerManagerIntf {
@Override
public boolean deliverEvent(String pubKey, String event) {
if (null != pubKey && !CMActions.manager.nodeCenterConn.getNodeId().equals(pubKey)) {
LOGGER.info("Deliver event message in node " + pubKey.substring(0, 6));
LOGGER.info("Deliver event message to node " + pubKey.substring(0, 6));
JsonObject msg = new JsonObject();
msg.addProperty("action", "deliverEvent");
msg.addProperty("data", event);