Skip to content

Commit

Permalink
Fixes alibaba#826
Browse files Browse the repository at this point in the history
  • Loading branch information
hxy1991 committed Feb 28, 2019
1 parent f62c66e commit 41e6ec9
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.slf4j.impl.StaticLoggerBinder;

/**
* Support for Logback version 0.9.19 or higher
* Support for Logback version 1.0.8 or higher
*
* @author <a href="mailto:[email protected]">hxy1991</a>
* @since 0.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void run() {
new DiskFileWriter().run();
}
} catch (Throwable e) {
NAMING_LOGGER.error("NA", "failed to backup file on startup.", e);
NAMING_LOGGER.error("[NA] failed to backup file on startup.", e);
}

}
Expand Down Expand Up @@ -137,7 +137,7 @@ public void run() {
}

} catch (Throwable e) {
NAMING_LOGGER.error("NA", "failed to read failover switch.", e);
NAMING_LOGGER.error("[NA] failed to read failover switch.", e);
}
}
}
Expand Down Expand Up @@ -182,12 +182,12 @@ public void run() {
try {
dom = JSON.parseObject(json, ServiceInfo.class);
} catch (Exception e) {
NAMING_LOGGER.error("NA", "error while parsing cached dom : " + json, e);
NAMING_LOGGER.error("[NA] error while parsing cached dom : " + json, e);
}
}

} catch (Exception e) {
NAMING_LOGGER.error("NA", "failed to read cache for dom: " + file.getName(), e);
NAMING_LOGGER.error("[NA] failed to read cache for dom: " + file.getName(), e);
} finally {
try {
if (reader != null) {
Expand All @@ -202,7 +202,7 @@ public void run() {
}
}
} catch (Exception e) {
NAMING_LOGGER.error("NA", "failed to read cache file", e);
NAMING_LOGGER.error("[NA] failed to read cache file", e);
}

if (domMap.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public Thread newThread(Runnable r) {
}

public void addBeatInfo(String dom, BeatInfo beatInfo) {
NAMING_LOGGER.info("BEAT", "adding beat: {} to beat map.", beatInfo);
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
dom2Beat.put(buildKey(dom, beatInfo.getIp(), beatInfo.getPort()), beatInfo);
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
}

public void removeBeatInfo(String dom, String ip, int port) {
NAMING_LOGGER.info("BEAT", "removing beat: {}:{}:{} from beat map.", dom, ip, port);
NAMING_LOGGER.info("[BEAT] removing beat: {}:{}:{} from beat map.", dom, ip, port);
dom2Beat.remove(buildKey(dom, ip, port));
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
}
Expand All @@ -88,7 +88,7 @@ public void run() {
executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
}
} catch (Exception e) {
NAMING_LOGGER.error("CLIENT-BEAT", "Exception while scheduling beat.", e);
NAMING_LOGGER.error("[CLIENT-BEAT] Exception while scheduling beat.", e);
} finally {
executorService.schedule(this, clientBeatInterval, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void write(ServiceInfo dom, String dir) {
ConcurrentDiskUtil.writeFileContent(file, keyContentBuffer.toString(), Charset.defaultCharset().toString());

} catch (Throwable e) {
NAMING_LOGGER.error("NA", "failed to write cache for dom:" + dom.getName(), e);
NAMING_LOGGER.error("[NA] failed to write cache for dom:" + dom.getName(), e);
}
}

Expand Down Expand Up @@ -119,11 +119,11 @@ public static Map<String, ServiceInfo> read(String cacheDir) {
ips.add(JSON.parseObject(json, Instance.class));
}
} catch (Throwable e) {
NAMING_LOGGER.error("NA", "error while parsing cache file: " + json, e);
NAMING_LOGGER.error("[NA] error while parsing cache file: " + json, e);
}
}
} catch (Exception e) {
NAMING_LOGGER.error("NA", "failed to read cache for dom: " + file.getName(), e);
NAMING_LOGGER.error("[NA] failed to read cache for dom: " + file.getName(), e);
} finally {
try {
if (reader != null) {
Expand All @@ -143,7 +143,7 @@ public static Map<String, ServiceInfo> read(String cacheDir) {

}
} catch (Throwable e) {
NAMING_LOGGER.error("NA", "failed to read cache file", e);
NAMING_LOGGER.error("[NA] failed to read cache file", e);
}

return domMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Thread newThread(Runnable r) {

public void addListener(ServiceInfo serviceInfo, String clusters, EventListener listener) {

NAMING_LOGGER.info("LISTENER", "adding " + serviceInfo.getName() + " with " + clusters + " to listener map");
NAMING_LOGGER.info("[LISTENER] adding " + serviceInfo.getName() + " with " + clusters + " to listener map");
List<EventListener> observers = Collections.synchronizedList(new ArrayList<EventListener>());
observers.add(listener);

Expand All @@ -72,7 +72,7 @@ public void addListener(ServiceInfo serviceInfo, String clusters, EventListener

public void removeListener(String serviceName, String clusters, EventListener listener) {

NAMING_LOGGER.info("LISTENER", "removing " + serviceName + " with " + clusters + " from listener map");
NAMING_LOGGER.info("[LISTENER] removing " + serviceName + " with " + clusters + " from listener map");

List<EventListener> observers = observerMap.get(ServiceInfo.getKey(serviceName, clusters));
if (observers != null) {
Expand Down Expand Up @@ -130,7 +130,7 @@ public void run() {
}

} catch (Exception e) {
NAMING_LOGGER.error("NA", "notify error for service: "
NAMING_LOGGER.error("[NA] notify error for service: "
+ serviceInfo.getName() + ", clusters: " + serviceInfo.getClusters(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ public ServiceInfo getServiceInfo(final String serviceName, final String cluster
try {
serviceObj.wait(updateHoldInterval);
} catch (InterruptedException e) {
NAMING_LOGGER.error("[getServiceInfo]",
"serviceName:" + serviceName + ", clusters:" + clusters, e);
NAMING_LOGGER.error("[getServiceInfo] serviceName:" + serviceName + ", clusters:" + clusters, e);
}
}
}
Expand Down Expand Up @@ -278,7 +277,7 @@ public void updateServiceNow(String serviceName, String clusters) {
processServiceJSON(result);
}
} catch (Exception e) {
NAMING_LOGGER.error("NA", "failed to update serviceName: " + serviceName, e);
NAMING_LOGGER.error("[NA] failed to update serviceName: " + serviceName, e);
} finally {
if (oldService != null) {
synchronized (oldService) {
Expand All @@ -292,7 +291,7 @@ public void refreshOnly(String serviceName, String clusters) {
try {
serverProxy.queryList(serviceName, clusters, pushReceiver.getUDPPort(), false);
} catch (Exception e) {
NAMING_LOGGER.error("NA", "failed to update serviceName: " + serviceName, e);
NAMING_LOGGER.error("[NA] failed to update serviceName: " + serviceName, e);
}
}

Expand Down Expand Up @@ -330,7 +329,7 @@ public void run() {

lastRefTime = serviceObj.getLastRefTime();
} catch (Throwable e) {
NAMING_LOGGER.warn("NA", "failed to update serviceName: " + serviceName, e);
NAMING_LOGGER.warn("[NA] failed to update serviceName: " + serviceName, e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Thread newThread(Runnable r) {

executorService.execute(this);
} catch (Exception e) {
NAMING_LOGGER.error("NA", "init udp socket failed", e);
NAMING_LOGGER.error("[NA] init udp socket failed", e);
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public void run() {
udpSocket.send(new DatagramPacket(ack.getBytes(Charset.forName("UTF-8")),
ack.getBytes(Charset.forName("UTF-8")).length, packet.getSocketAddress()));
} catch (Exception e) {
NAMING_LOGGER.error("NA", "error while receiving push data", e);
NAMING_LOGGER.error("[NA] error while receiving push data", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public static HttpResult request(String url, List<String> headers, Map<String, S
+ InetAddress.getByName(conn.getURL().getHost()).getHostAddress());
}
} catch (Exception e1) {
NAMING_LOGGER.error("NA", "failed to request ", e1);
NAMING_LOGGER.error("[NA] failed to request ", e1);
//ignore
}

NAMING_LOGGER.error("NA", "failed to request ", e);
NAMING_LOGGER.error("[NA] failed to request ", e);

return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void refreshSrvIfNeed() {
}

if (!CollectionUtils.isEqualCollection(list, serversFromEndpoint)) {
NAMING_LOGGER.info("SERVER-LIST", "server list is updated: " + list);
NAMING_LOGGER.info("[SERVER-LIST] server list is updated: " + list);
}

serversFromEndpoint = list;
Expand All @@ -169,7 +169,7 @@ private void refreshSrvIfNeed() {

public void registerService(String serviceName, Instance instance) throws NacosException {

NAMING_LOGGER.info("REGISTER-SERVICE", "{} registering service {} with instance: {}",
NAMING_LOGGER.info("[REGISTER-SERVICE] {} registering service {} with instance: {}",
namespaceId, serviceName, instance);

final Map<String, String> params = new HashMap<String, String>(8);
Expand All @@ -189,7 +189,7 @@ public void registerService(String serviceName, Instance instance) throws NacosE

public void deregisterService(String serviceName, String ip, int port, String cluster) throws NacosException {

NAMING_LOGGER.info("DEREGISTER-SERVICE", "{} deregistering service {} with instance: {}:{}@{}",
NAMING_LOGGER.info("[DEREGISTER-SERVICE] {} deregistering service {} with instance: {}:{}@{}",
namespaceId, serviceName, ip, port, cluster);

final Map<String, String> params = new HashMap<String, String>(8);
Expand Down Expand Up @@ -218,7 +218,7 @@ public String queryList(String serviceName, String clusters, int udpPort, boolea

public long sendBeat(BeatInfo beatInfo) {
try {
NAMING_LOGGER.info("BEAT", "{} sending beat to server: {}", namespaceId, beatInfo.toString());
NAMING_LOGGER.info("[BEAT] {} sending beat to server: {}", namespaceId, beatInfo.toString());
Map<String, String> params = new HashMap<String, String>(4);
params.put("beat", JSON.toJSONString(beatInfo));
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, namespaceId);
Expand All @@ -230,7 +230,7 @@ public long sendBeat(BeatInfo beatInfo) {
return jsonObject.getLong("clientBeatInterval");
}
} catch (Exception e) {
NAMING_LOGGER.error("CLIENT-BEAT", "failed to send beat: " + JSON.toJSONString(beatInfo), e);
NAMING_LOGGER.error("[CLIENT-BEAT] failed to send beat: " + JSON.toJSONString(beatInfo), e);
}
return 0L;
}
Expand Down Expand Up @@ -337,7 +337,7 @@ public String callServer(String api, Map<String, String> params, String curServe
return StringUtils.EMPTY;
}

NAMING_LOGGER.error("CALL-SERVER", "failed to req API:" + HttpClient.getPrefix() + curServer
NAMING_LOGGER.error("[CALL-SERVER] failed to req API:" + HttpClient.getPrefix() + curServer
+ api + ". code:"
+ result.code + " msg: " + result.content);

Expand Down Expand Up @@ -368,7 +368,7 @@ public String reqAPI(String api, Map<String, String> params, List<String> server
try {
return callServer(api, params, server, method);
} catch (Exception e) {
NAMING_LOGGER.error("NA", "req api:" + api + " failed, server(" + server, e);
NAMING_LOGGER.error("[NA] req api:" + api + " failed, server(" + server, e);
}

index = (index + 1) % servers.size();
Expand All @@ -381,7 +381,7 @@ public String reqAPI(String api, Map<String, String> params, List<String> server
try {
return callServer(api, params, nacosDomain);
} catch (Exception e) {
NAMING_LOGGER.error("NA", "req api:" + api + " failed, server(" + nacosDomain, e);
NAMING_LOGGER.error("[NA] req api:" + api + " failed, server(" + nacosDomain, e);
}
}

Expand Down

0 comments on commit 41e6ec9

Please sign in to comment.