Skip to content

Commit 3ac8995

Browse files
committed
Improve logging
1 parent 69ac477 commit 3ac8995

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

src/integrationTest/java/com/hivemq/extensions/discovery/azure/AzureDiscoveryExtensionIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ private HiveMQTestContainerExtension createHiveMQNode(final @NotNull String conn
263263
.withExtension(extensionDir.toFile())
264264
.withHiveMQConfig(new File("src/integrationTest/resources/config.xml"))
265265
.withNetwork(network)
266-
.withLogLevel(Level.DEBUG)
267266
.waitingFor(Wait.forLogMessage(".*Started HiveMQ in.*\\n", 1));
268267
}
269268

src/main/java/com/hivemq/extensions/discovery/azure/callback/AzureClusterDiscoveryCallback.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void init(
6363
try {
6464
azureStorageClient.createOrUpdate();
6565
} catch (final IllegalStateException | IllegalArgumentException ex) {
66-
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
66+
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
6767
return;
6868
}
6969

@@ -81,7 +81,7 @@ public void init(
8181
saveOwnFile(clusterDiscoveryInput.getOwnClusterId(), clusterDiscoveryInput.getOwnAddress());
8282
clusterDiscoveryOutput.provideCurrentNodes(getNodeAddresses());
8383
} catch (final Exception ex) {
84-
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
84+
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
8585
}
8686

8787
}
@@ -94,7 +94,7 @@ public void reload(
9494
try {
9595
azureStorageClient.createOrUpdate();
9696
} catch (final IllegalStateException | IllegalArgumentException ex) {
97-
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
97+
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
9898
return;
9999
}
100100

@@ -116,7 +116,7 @@ public void reload(
116116

117117
clusterDiscoveryOutput.provideCurrentNodes(getNodeAddresses());
118118
} catch (final Exception ex) {
119-
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
119+
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
120120
}
121121
}
122122

@@ -127,7 +127,7 @@ public void destroy(final @NotNull ClusterDiscoveryInput clusterDiscoveryInput)
127127
deleteOwnFile(clusterDiscoveryInput.getOwnClusterId());
128128
}
129129
} catch (final RuntimeException ex) {
130-
log.warn("Destroy of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
130+
log.warn("Destroy of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
131131
}
132132

133133
}
@@ -177,7 +177,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
177177
try {
178178
azureStorageClient.deleteBlob(blobKey);
179179
} catch (final Exception ex) {
180-
log.warn("Could not delete expired Azure Blob file '{}'. {}", blobKey, ex.getMessage());
180+
log.warn("Could not delete expired Azure Blob file '{}'. {}", blobKey, getRootCause(ex));
181181
}
182182
} else {
183183
nodeAddresses.add(nodeFile.getClusterNodeAddress());
@@ -203,7 +203,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
203203
}
204204
});
205205
} catch (final Exception ex) {
206-
log.warn("Could not get Azure Blobs. {}", ex.getMessage());
206+
log.warn("Could not get Azure Blobs. {}", getRootCause(ex).getMessage());
207207
}
208208

209209
return clusterNodeFiles;
@@ -215,7 +215,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
215215
try {
216216
fileContent = azureStorageClient.getBlobContent(blob.getName());
217217
} catch (RuntimeException e) {
218-
log.warn("An error occurred while downloading the Azure Blob. {}", e.getMessage());
218+
log.warn("An error occurred while downloading the Azure Blob. {}", getRootCause(e).getMessage());
219219
return null;
220220
}
221221

@@ -235,4 +235,14 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
235235
void setAzureStorageClient(final @NotNull AzureStorageClient azureStorageClient) {
236236
this.azureStorageClient = azureStorageClient;
237237
}
238+
239+
private @NotNull Throwable getRootCause(final @NotNull Throwable e) {
240+
Throwable cause;
241+
Throwable result = e;
242+
243+
while(null != (cause = result.getCause()) && (result != cause) ) {
244+
result = cause;
245+
}
246+
return result;
247+
}
238248
}

src/main/java/com/hivemq/extensions/discovery/azure/client/AzureStorageClient.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public boolean existsContainer() throws RuntimeException {
7575
return containerClient.exists();
7676
} catch (final BlobStorageException blobStorageException) {
7777
throw new RuntimeException("Azure Storage Container existence check failed with status code " +
78-
blobStorageException.getStatusCode() + " and error code " + blobStorageException.getErrorCode());
78+
blobStorageException.getStatusCode() + " and error code " + blobStorageException.getErrorCode() + ".");
7979
}
8080
}
8181

@@ -93,7 +93,7 @@ public void createContainer() throws RuntimeException {
9393
} else {
9494
throw new RuntimeException(
9595
"Azure Storage Container creation failed with status code " + error.getStatusCode() +
96-
" and error code " + error.getErrorCode());
96+
" and error code " + error.getErrorCode() + ".");
9797
}
9898
}
9999
}
@@ -107,7 +107,7 @@ public void saveBlob(final @NotNull String blobName, final @NotNull String conte
107107
} catch (final BlobStorageException blobStorageException) {
108108
throw new RuntimeException(
109109
"Azure Storage Blob upload failed with status code " + blobStorageException.getStatusCode() +
110-
" and error code " + blobStorageException.getErrorCode());
110+
" and error code " + blobStorageException.getErrorCode() + ".");
111111
}
112112
}
113113

@@ -116,10 +116,11 @@ public void deleteBlob(final @NotNull String blobName) throws RuntimeException {
116116

117117
try {
118118
blob.delete();
119-
} catch (final BlobStorageException blobStorageException) {
119+
}
120+
catch (final BlobStorageException blobStorageException) {
120121
throw new RuntimeException(
121122
"Azure Storage Blob delete failed with status code " + blobStorageException.getStatusCode() +
122-
" and error code " + blobStorageException.getErrorCode());
123+
" and error code " + blobStorageException.getErrorCode() + ".");
123124
}
124125
}
125126

@@ -130,10 +131,11 @@ public String getBlobContent(final @NotNull String blobName) throws RuntimeExcep
130131

131132
try {
132133
blobClient.download(outputStream);
133-
} catch (final BlobStorageException blobStorageException) {
134+
}
135+
catch (final BlobStorageException blobStorageException) {
134136
throw new RuntimeException(
135137
"Azure Storage Blob download failed with status code " + blobStorageException.getStatusCode() +
136-
" and error code " + blobStorageException.getErrorCode());
138+
" and error code " + blobStorageException.getErrorCode() + ".");
137139
}
138140

139141
return outputStream.toString();
@@ -147,7 +149,7 @@ public Iterator<BlobItem> getBlobs(final @NotNull String filePrefix) throws Runt
147149
} catch (final BlobStorageException blobStorageException) {
148150
throw new RuntimeException(
149151
"Azure Storage Blobs retrieval failed with status code " + blobStorageException.getStatusCode() +
150-
" and error code " + blobStorageException.getErrorCode());
152+
" and error code " + blobStorageException.getErrorCode() + ".");
151153
}
152154
}
153155

src/main/java/com/hivemq/extensions/discovery/azure/config/ConfigReader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover
8888

8989
final String connectionString = azureDiscoveryConfig.getConnectionString();
9090
if (isNullOrBlank(connectionString)) {
91-
logger.warn("The Connection String of the configuration file was empty.");
91+
logger.warn("The Connection String in the configuration file was empty.");
9292
return false;
9393
}
9494

9595
final String containerName = azureDiscoveryConfig.getContainerName();
9696
if (isNullOrBlank(containerName)) {
97-
logger.warn("The Container Name of the configuration file was empty.");
97+
logger.warn("The Container Name in the configuration file was empty.");
9898
return false;
9999
}
100100

@@ -103,12 +103,12 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover
103103
fileExpirationInSeconds = azureDiscoveryConfig.getFileExpirationInSeconds();
104104
} catch (final UnsupportedOperationException e) {
105105
logger.warn(
106-
"The File Expiration Interval of the configuration file was empty.");
106+
"The File Expiration Interval in the configuration file was not valid. {}.", e.getMessage());
107107
return false;
108108
}
109109
if (fileExpirationInSeconds < 0) {
110110
logger.warn(
111-
"The File Expiration Interval of the configuration file was negative.");
111+
"The File Expiration Interval in the configuration file was negative.");
112112
return false;
113113
}
114114

@@ -117,12 +117,12 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover
117117
fileUpdateIntervalInSeconds = azureDiscoveryConfig.getFileUpdateIntervalInSeconds();
118118
} catch (final UnsupportedOperationException e) {
119119
logger.warn(
120-
"The File Update Interval of the configuration file was empty.");
120+
"The File Update Interval in the configuration file was not valid. {}.", e.getMessage());
121121
return false;
122122
}
123123
if (fileUpdateIntervalInSeconds < 0) {
124124
logger.warn(
125-
"The File Update Interval of the configuration file was negative.");
125+
"The File Update Interval in the configuration file was negative.");
126126
return false;
127127
}
128128

0 commit comments

Comments
 (0)