Skip to content

Commit

Permalink
Change Stacktraces to be trace
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBrand committed Aug 23, 2023
1 parent 22184ac commit 2a26368
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.hivemq.cli.mqtt.MqttClientExecutor;
import com.hivemq.cli.utils.LoggerUtils;
import com.hivemq.client.mqtt.MqttClient;
import com.hivemq.client.mqtt.exceptions.ConnectionFailedException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.tinylog.Logger;
Expand Down Expand Up @@ -109,7 +108,7 @@ public SubscribeCommand(final @NotNull MqttClientExecutor mqttClientExecutor) {

try {
mqttClientExecutor.subscribe(subscribeClient, subscribeOptions);
} catch (final ConnectionFailedException exception) {
} catch (final Exception exception) {
LoggerUtils.logCommandError("Unable to subscribe", exception, debugOptions);
return 1;
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/hivemq/cli/mqtt/MqttClientExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ void mqtt5Subscribe(
.subscribe(subscribeMessage, new SubscribeMqtt5PublishCallback(subscribeOptions, client))
.whenComplete((subAck, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed SUBSCRIBE to TOPIC '{}': {}",
Logger.error("{} failed SUBSCRIBE to TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
if (throwable instanceof Mqtt5SubAckException) {
Logger.debug(((Mqtt5SubAckException) throwable).getMqttMessage());
}
Logger.trace(throwable);
} else {
final ClientKey clientKey = ClientKey.of(client);
getClientDataMap().get(clientKey).addSubscription(MqttTopicFilter.of(topic));
Expand All @@ -150,14 +150,14 @@ void mqtt3Subscribe(
.subscribe(subscribeMessage, new SubscribeMqtt3PublishCallback(subscribeOptions, client))
.whenComplete((subAck, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed SUBSCRIBE to TOPIC '{}': {}",
Logger.error("{} failed SUBSCRIBE to TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
if (throwable instanceof Mqtt3SubAckException) {
Logger.debug(((Mqtt3SubAckException) throwable).getMqttMessage());
}
Logger.trace(throwable);
} else {
getClientDataMap().get(ClientKey.of(client)).addSubscription(MqttTopicFilter.of(topic));

Expand Down Expand Up @@ -205,8 +205,7 @@ void mqtt5Publish(

client.toAsync().publish(publishMessage).whenComplete((publishResult, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed PUBLISH to TOPIC '{}': {}",
Logger.error("{} failed PUBLISH to TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
Expand All @@ -215,6 +214,7 @@ void mqtt5Publish(
} else if (throwable instanceof Mqtt5PubRecException) {
Logger.debug(((Mqtt5PubRecException) throwable).getMqttMessage());
}
Logger.trace(throwable);
} else {
Logger.debug("{} received PUBLISH acknowledgement {}", clientLogPrefix, publishResult);
}
Expand Down Expand Up @@ -245,11 +245,11 @@ void mqtt3Publish(

client.toAsync().publish(publishMessage).whenComplete((publishResult, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed PUBLISH to TOPIC '{}': {}",
Logger.error("{} failed PUBLISH to TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
Logger.trace(throwable);
} else {
Logger.debug("{} received PUBLISH acknowledgement {}", clientLogPrefix, publishResult);
}
Expand All @@ -270,14 +270,14 @@ void mqtt5Unsubscribe(final @NotNull Mqtt5Client client, final @NotNull Unsubscr

client.toAsync().unsubscribe(unsubscribeMessage).whenComplete((unsubAck, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed UNSUBSCRIBE from TOPIC '{}': {}",
Logger.error("{} failed UNSUBSCRIBE from TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
if (throwable instanceof Mqtt5UnsubAckException) {
Logger.debug(((Mqtt5UnsubAckException) throwable).getMqttMessage());
}
Logger.trace(throwable);
} else {
getClientDataMap().get(ClientKey.of(client)).removeSubscription(MqttTopicFilter.of(topic));

Expand All @@ -298,11 +298,11 @@ void mqtt3Unsubscribe(final @NotNull Mqtt3Client client, final @NotNull Unsubscr

client.toAsync().unsubscribe(unsubscribeMessage).whenComplete((unsubAck, throwable) -> {
if (throwable != null) {
Logger.error(throwable,
"{} failed UNSUBSCRIBE from TOPIC '{}': {}",
Logger.error("{} failed UNSUBSCRIBE from TOPIC '{}': {}",
clientLogPrefix,
topic,
Throwables.getRootCause(throwable).getMessage());
Logger.trace(throwable);
} else {
getClientDataMap().get(ClientKey.of(client)).removeSubscription(MqttTopicFilter.of(topic));
Logger.debug("{} received UNSUBACK", clientLogPrefix);
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/hivemq/cli/utils/LoggerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ public static void logCommandError(
final @NotNull String message,
final @NotNull Exception exception,
final @NotNull DebugOptions debugOptions) {
if (debugOptions.isDebug() || debugOptions.isVerbose()) {
Logger.error(exception, message);
final String exceptionMessage = Throwables.getRootCause(exception).getMessage();
if (exceptionMessage != null) {
Logger.error("{}. Reason: '{}'", message, exceptionMessage);
} else {
final String exceptionMessage = Throwables.getRootCause(exception).getMessage();
if (exceptionMessage != null) {
Logger.error("{}. Reason: '{}'", message, exceptionMessage);
} else {
Logger.error("{}. Use '-d' option to get more detailed information.", message);
}
Logger.error("{}.", message);
}
if (!debugOptions.isDebug()) {
Logger.error("Use '-d' or 'v' option to get more detailed information.");
}
if (debugOptions.isVerbose()) {
Logger.error(exception);
}
}

Expand Down

0 comments on commit 2a26368

Please sign in to comment.