Skip to content

Commit

Permalink
[openhabcloud] logging level tuning
Browse files Browse the repository at this point in the history
Signed-off-by: Sami Salonen <[email protected]>
  • Loading branch information
ssalonen committed May 15, 2022
1 parent 5f79367 commit b0af2ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void call(Object... args) {
type = "<unknown type>";
}
}
logger.debug("Socket.IO Packet: {} ({})", type, packetTypeIndex);
logger.trace("Socket.IO Packet: {} ({})", type, packetTypeIndex);
})//
;

Expand Down Expand Up @@ -265,19 +265,25 @@ public void call(Object... args) {
args -> logger.debug("Socket.IO re-connect attempts failed. Stopping reconnection."))//
.on(Socket.EVENT_DISCONNECT, args -> {
if (args.length > 0) {
logger.debug("Socket.IO disconnected: {}", args[0]);
logger.info("Socket.IO disconnected: {}", args[0]);
} else {
logger.debug("Socket.IO disconnected");
logger.info("Socket.IO disconnected");
}
isConnected = false;
onDisconnect();
})//
.on(Socket.EVENT_ERROR, args -> {
if (CloudClient.this.socket.connected()) {
if (logger.isDebugEnabled() && args.length > 0) {
logger.error("Error during communication: {}", args[0]);
if (args.length > 0) {
if (args[0] instanceof Exception) {
Exception e = (Exception) args[0];
logger.warn("Error during communication: {} {}", e.getClass().getSimpleName(),
e.getMessage());
} else {
logger.warn("Error during communication: {}", args[0]);
}
} else {
logger.error("Error during communication");
logger.warn("Error during communication");
}
} else {
// We are not connected currently, manual reconnection is needed to keep trying to
Expand All @@ -295,30 +301,31 @@ public void call(Object... args) {
// errors that are retried by the library automatically!
long delay = reconnectBackoff.duration();
// Try reconnecting on connection errors
if (logger.isDebugEnabled() && args.length > 0) {
if (args.length > 0) {
if (args[0] instanceof Exception) {
Exception e = (Exception) args[0];
logger.error(
logger.warn(
"Error connecting to the openHAB Cloud instance: {} {}. Reconnecting after {} ms.",
e.getClass().getSimpleName(), e.getMessage(), delay);
} else {
logger.error(
logger.warn(
"Error connecting to the openHAB Cloud instance: {}. Reconnecting after {} ms.",
args[0], delay);
}
} else {
logger.error("Error connecting to the openHAB Cloud instance. Reconnecting.");
logger.warn("Error connecting to the openHAB Cloud instance. Reconnecting.");
}
socket.close();
sleepSocketIO(delay);
socket.connect();
}
})//

.on(Socket.EVENT_PING, args -> logger.debug("Socket.IO ping"))//
.on(Socket.EVENT_PONG, args -> logger.debug("Socket.IO pong: {} ms", args[0]))//
.on("request", args -> onEvent("request", (JSONObject) args[0]))//
.on("cancel", args -> onEvent("cancel", (JSONObject) args[0]))//
.on("command", args -> onEvent("command", (JSONObject) args[0]))//
.on(Socket.EVENT_PING, args -> logger.debug("Socket.IO ping"))//
.on(Socket.EVENT_PONG, args -> logger.debug("Socket.IO pong: {} ms", args[0]))//
;
socket.connect();
}
Expand All @@ -334,13 +341,6 @@ public void onConnect() {
isConnected = true;
}

private static String sensored(String secret) {
if (secret.length() < 4) {
return "*******";
}
return secret.substring(0, 2) + "..." + secret.substring(secret.length() - 2, secret.length());
}

/**
* Callback method for socket.io client which is called when disconnect occurs
*/
Expand Down Expand Up @@ -694,4 +694,11 @@ private void sleepSocketIO(long delay) {
}
});
}

private static String sensored(String secret) {
if (secret.length() < 4) {
return "*******";
}
return secret.substring(0, 2) + "..." + secret.substring(secret.length() - 2, secret.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,6 @@ protected void modified(Map<String, ?> config) {
NotificationAction.cloudService = this;
}

private static String sensored(String secret) {
if (secret.length() < 4) {
return "*******";
}
return secret.substring(0, 2) + "..." + secret.substring(secret.length() - 2, secret.length());
}

@Override
public String getActionClassName() {
return NotificationAction.class.getCanonicalName();
Expand Down Expand Up @@ -328,6 +321,13 @@ private String getSecret() {
return newSecretString;
}

private static String sensored(String secret) {
if (secret.length() < 4) {
return "*******";
}
return secret.substring(0, 2) + "..." + secret.substring(secret.length() - 2, secret.length());
}

@Override
public void sendCommand(String itemName, String commandString) {
try {
Expand Down

0 comments on commit b0af2ad

Please sign in to comment.