Skip to content

Commit a7fba99

Browse files
authored
Merge pull request #294 from scalecube/update/enhance-logging
Enhanced logging
2 parents d1cfcd9 + a022c30 commit a7fba99

File tree

12 files changed

+238
-226
lines changed

12 files changed

+238
-226
lines changed

cluster-testlib/src/main/java/io/scalecube/cluster/utils/NetworkEmulator.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public OutboundSettings outboundSettings(Address destination) {
7070
public void outboundSettings(Address destination, int lossPercent, int meanDelay) {
7171
OutboundSettings settings = new OutboundSettings(lossPercent, meanDelay);
7272
outboundSettings.put(destination, settings);
73-
LOGGER.debug("Set outbound settings {} from {} to {}", settings, address, destination);
73+
LOGGER.debug("[{}] Set outbound settings {} to {}", address, settings, destination);
7474
}
7575

7676
/**
@@ -81,21 +81,21 @@ public void outboundSettings(Address destination, int lossPercent, int meanDelay
8181
*/
8282
public void setDefaultOutboundSettings(int lossPercent, int meanDelay) {
8383
defaultOutboundSettings = new OutboundSettings(lossPercent, meanDelay);
84-
LOGGER.debug("Set default outbound settings {} for {}", defaultOutboundSettings, address);
84+
LOGGER.debug("[{}] Set default outbound settings {}", address, defaultOutboundSettings);
8585
}
8686

8787
/** Blocks outbound messages to all destinations. */
8888
public void blockAllOutbound() {
8989
outboundSettings.clear();
9090
setDefaultOutboundSettings(100, 0);
91-
LOGGER.debug("Blocked outbound from {} to all destinations", address);
91+
LOGGER.debug("[{}] Blocked outbound to all destinations", address);
9292
}
9393

9494
/** Unblocks outbound messages to all destinations. */
9595
public void unblockAllOutbound() {
9696
outboundSettings.clear();
9797
setDefaultOutboundSettings(0, 0);
98-
LOGGER.debug("Unblocked outbound from {} to all destinations", address);
98+
LOGGER.debug("[{}] Unblocked outbound to all destinations", address);
9999
}
100100

101101
/**
@@ -116,7 +116,7 @@ public void blockOutbound(Collection<Address> destinations) {
116116
for (Address destination : destinations) {
117117
outboundSettings.put(destination, new OutboundSettings(100, 0));
118118
}
119-
LOGGER.debug("Blocked outbound from {} to {}", address, destinations);
119+
LOGGER.debug("[{}] Blocked outbound to {}", address, destinations);
120120
}
121121

122122
/**
@@ -135,7 +135,7 @@ public void unblockOutbound(Address... destinations) {
135135
*/
136136
public void unblockOutbound(Collection<Address> destinations) {
137137
destinations.forEach(outboundSettings::remove);
138-
LOGGER.debug("Unblocked outbound from {} to {}", address, destinations);
138+
LOGGER.debug("[{}] Unblocked outbound {}", address, destinations);
139139
}
140140

141141
/**
@@ -221,7 +221,7 @@ public InboundSettings inboundSettings(Address destination) {
221221
public void inboundSettings(Address destination, boolean shallPass) {
222222
InboundSettings settings = new InboundSettings(shallPass);
223223
inboundSettings.put(destination, settings);
224-
LOGGER.debug("Set inbound settings {} from {} to {}", settings, address, destination);
224+
LOGGER.debug("[{}] Set inbound settings {} to {}", address, settings, destination);
225225
}
226226

227227
/**
@@ -231,21 +231,21 @@ public void inboundSettings(Address destination, boolean shallPass) {
231231
*/
232232
public void setDefaultInboundSettings(boolean shallPass) {
233233
defaultInboundSettings = new InboundSettings(shallPass);
234-
LOGGER.debug("Set default inbound settings {} for {}", defaultInboundSettings, address);
234+
LOGGER.debug("[{}] Set default inbound settings {}", address, defaultInboundSettings);
235235
}
236236

237237
/** Blocks inbound messages from all destinations. */
238238
public void blockAllInbound() {
239239
inboundSettings.clear();
240240
setDefaultInboundSettings(false);
241-
LOGGER.debug("Blocked inbound to {} from all destinations", address);
241+
LOGGER.debug("[{}] Blocked inbound from all destinations", address);
242242
}
243243

244244
/** Unblocks inbound messages to all destinations. */
245245
public void unblockAllInbound() {
246246
inboundSettings.clear();
247247
setDefaultInboundSettings(true);
248-
LOGGER.debug("Unblocked inbound to {} from all destinations", address);
248+
LOGGER.debug("[{}] Unblocked inbound from all destinations", address);
249249
}
250250

251251
/**
@@ -266,7 +266,7 @@ public void blockInbound(Collection<Address> destinations) {
266266
for (Address destination : destinations) {
267267
inboundSettings.put(destination, new InboundSettings(false));
268268
}
269-
LOGGER.debug("Blocked inbound to {} from {}", address, destinations);
269+
LOGGER.debug("[{}] Blocked inbound from {}", address, destinations);
270270
}
271271

272272
/**
@@ -285,7 +285,7 @@ public void unblockInbound(Address... destinations) {
285285
*/
286286
public void unblockInbound(Collection<Address> destinations) {
287287
destinations.forEach(inboundSettings::remove);
288-
LOGGER.debug("Unblocked inbound to {} from {}", address, destinations);
288+
LOGGER.debug("[{}] Unblocked inbound from {}", address, destinations);
289289
}
290290

291291
/**

cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ private void initLifecycle() {
118118
.then(doStart())
119119
.doOnSuccess(avoid -> onStart.onComplete())
120120
.doOnError(onStart::onError)
121-
.subscribe(
122-
null,
123-
th -> {
124-
LOGGER.error("Cluster member {} failed on start: ", localMember, th);
125-
shutdown.onComplete();
126-
});
121+
.subscribe(null, th -> LOGGER.error("[{}][doStart] Exception occurred:", localMember, th));
127122

128-
shutdown //
123+
shutdown
129124
.then(doShutdown())
130125
.doFinally(s -> onShutdown.onComplete())
131-
.subscribe();
126+
.subscribe(
127+
null,
128+
th ->
129+
LOGGER.warn("[{}][doShutdown] Exception occurred: {}", localMember, th.toString()));
132130
}
133131

134132
/**
@@ -352,7 +350,7 @@ private ObjectInstance startJmxMonitor0() throws Exception {
352350
}
353351

354352
private void onError(Throwable th) {
355-
LOGGER.error("Received unexpected error: ", th);
353+
LOGGER.error("[{}] Received unexpected error:", localMember, th);
356354
}
357355

358356
private Flux<Message> listenMessage() {
@@ -481,28 +479,25 @@ public void shutdown() {
481479
private Mono<Void> doShutdown() {
482480
return Mono.defer(
483481
() -> {
484-
LOGGER.info("Cluster member {} is shutting down", localMember);
482+
LOGGER.debug("[{}] Cluster member is shutting down", localMember);
485483
return Flux.concatDelayError(leaveCluster(), dispose(), transport.stop())
486484
.then()
487485
.doFinally(s -> scheduler.dispose())
488486
.doOnSuccess(
489-
avoid -> LOGGER.info("Cluster member {} has been shut down", localMember))
490-
.doOnError(
491-
th ->
492-
LOGGER.warn(
493-
"Cluster member {} failed on shutdown: {}", localMember, th.toString()));
487+
avoid -> LOGGER.debug("[{}] Cluster member has been shutdown", localMember));
494488
});
495489
}
496490

497491
private Mono<Void> leaveCluster() {
498492
return membership
499493
.leaveCluster()
500494
.subscribeOn(scheduler)
501-
.doOnSuccess(s -> LOGGER.debug("Cluster member {} has left a cluster", localMember))
495+
.doOnSubscribe(s -> LOGGER.debug("[{}] Cluster member is leaving a cluster", localMember))
496+
.doOnSuccess(s -> LOGGER.debug("[{}] Cluster member has left a cluster", localMember))
502497
.doOnError(
503498
ex ->
504-
LOGGER.info(
505-
"Cluster member {} failed on leaveCluster: {}", localMember, ex.toString()))
499+
LOGGER.warn(
500+
"[{}][leaveCluster] Exception occurred: {}", localMember, ex.toString()))
506501
.then();
507502
}
508503

0 commit comments

Comments
 (0)