Skip to content

Commit eaf3fbc

Browse files
committed
[cleanup] simplify logging debug/trace code
[logging] don't use anymore `if (logger.isTraceEnabled())` or `if (logger.isDebugEnabled())` Related to #52. (cherry picked from commit 95381d4) (cherry picked from commit 6d5ce44)
1 parent 68fdedf commit eaf3fbc

File tree

3 files changed

+18
-41
lines changed

3 files changed

+18
-41
lines changed

src/main/java/org/elasticsearch/cloud/azure/AzureComputeServiceImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public AzureComputeServiceImpl(Settings settings, SettingsFilter settingsFilter)
8383
// Check that we have all needed properties
8484
try {
8585
socketFactory = getSocketFactory(keystore, password);
86-
if (logger.isTraceEnabled()) logger.trace("creating new Azure client for [{}], [{}], [{}], [{}]",
87-
subscription_id, service_name, port_name);
86+
logger.trace("creating new Azure client for [{}], [{}], [{}]", subscription_id, service_name, port_name);
8887
} catch (Exception e) {
8988
// Can not start Azure Client
9089
logger.error("can not start azure client: {}", e.getMessage());
@@ -100,8 +99,8 @@ private InputStream getXML(String api) throws UnrecoverableKeyException, NoSuchA
10099
con.setSSLSocketFactory( socketFactory );
101100
con.setRequestProperty("x-ms-version", Azure.VERSION);
102101

103-
if (logger.isDebugEnabled()) logger.debug("calling azure REST API: {}", api);
104-
if (logger.isTraceEnabled()) logger.trace("get {} from azure", https_url);
102+
logger.debug("calling azure REST API: {}", api);
103+
logger.trace("get {} from azure", https_url);
105104

106105
return con.getInputStream();
107106
}
@@ -110,13 +109,13 @@ private InputStream getXML(String api) throws UnrecoverableKeyException, NoSuchA
110109
public Set<Instance> instances() {
111110
if (socketFactory == null) {
112111
// Azure plugin is disabled
113-
if (logger.isTraceEnabled()) logger.trace("azure plugin is disabled. Returning an empty list of nodes.");
112+
logger.trace("azure plugin is disabled. Returning an empty list of nodes.");
114113
return new HashSet<Instance>();
115114
} else {
116115
try {
117116
InputStream stream = getXML("/services/hostedservices/" + service_name + "?embed-detail=true");
118117
Set<Instance> instances = buildInstancesFromXml(stream, port_name);
119-
if (logger.isTraceEnabled()) logger.trace("get instances from azure: {}", instances);
118+
logger.trace("get instances from azure: {}", instances);
120119

121120
return instances;
122121

src/main/java/org/elasticsearch/cloud/azure/AzureStorageServiceImpl.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public AzureStorageServiceImpl(Settings settings, SettingsFilter settingsFilter)
7676

7777
try {
7878
if (account != null) {
79-
if (logger.isTraceEnabled()) logger.trace("creating new Azure storage client using account [{}], key [{}], blob [{}]",
80-
account, key, blob);
79+
logger.trace("creating new Azure storage client using account [{}], key [{}], blob [{}]", account, key, blob);
8180

8281
String storageConnectionString =
8382
"DefaultEndpointsProtocol=http;"
@@ -120,27 +119,20 @@ public void removeContainer(String container) throws URISyntaxException, Storage
120119
options.setRetryPolicyFactory(new RetryNoRetry());
121120
blob_container.deleteIfExists(options, null);
122121
*/
123-
if (logger.isTraceEnabled()) {
124-
logger.trace("removing container [{}]", container);
125-
}
122+
logger.trace("removing container [{}]", container);
126123
blob_container.deleteIfExists();
127124
}
128125

129126
@Override
130127
public void createContainer(String container) throws URISyntaxException, StorageException {
131128
CloudBlobContainer blob_container = client.getContainerReference(container);
132-
if (logger.isTraceEnabled()) {
133-
logger.trace("creating container [{}]", container);
134-
}
129+
logger.trace("creating container [{}]", container);
135130
blob_container.createIfNotExist();
136131
}
137132

138133
@Override
139134
public void deleteFiles(String container, String path) throws URISyntaxException, StorageException, ServiceException {
140-
if (logger.isTraceEnabled()) {
141-
logger.trace("delete files container [{}], path [{}]",
142-
container, path);
143-
}
135+
logger.trace("delete files container [{}], path [{}]", container, path);
144136

145137
// Container name must be lower case.
146138
CloudBlobContainer blob_container = client.getContainerReference(container);
@@ -150,10 +142,7 @@ public void deleteFiles(String container, String path) throws URISyntaxException
150142

151143
List<ListBlobsResult.BlobEntry> blobs = service.listBlobs(container, options).getBlobs();
152144
for (ListBlobsResult.BlobEntry blob : blobs) {
153-
if (logger.isTraceEnabled()) {
154-
logger.trace("removing in container [{}], path [{}], blob [{}]",
155-
container, path, blob.getName());
156-
}
145+
logger.trace("removing in container [{}], path [{}], blob [{}]", container, path, blob.getName());
157146
service.deleteBlob(container, blob.getName());
158147
}
159148
}
@@ -173,18 +162,12 @@ public boolean blobExists(String container, String blob) throws URISyntaxExcepti
173162

174163
@Override
175164
public void deleteBlob(String container, String blob) throws URISyntaxException, StorageException {
176-
if (logger.isTraceEnabled()) {
177-
logger.trace("delete blob for container [{}], blob [{}]",
178-
container, blob);
179-
}
165+
logger.trace("delete blob for container [{}], blob [{}]", container, blob);
180166

181167
// Container name must be lower case.
182168
CloudBlobContainer blob_container = client.getContainerReference(container);
183169
if (blob_container.exists()) {
184-
if (logger.isTraceEnabled()) {
185-
logger.trace("blob found. removing.",
186-
container, blob);
187-
}
170+
logger.trace("blob found. removing.", container, blob);
188171
// TODO A REVOIR
189172
CloudBlockBlob azureBlob = blob_container.getBlockBlobReference(blob);
190173
azureBlob.delete();
@@ -212,15 +195,11 @@ public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String container, St
212195
Iterable<ListBlobItem> blobs = blob_container.listBlobs(keyPath + prefix);
213196
for (ListBlobItem blob : blobs) {
214197
URI uri = blob.getUri();
215-
if (logger.isTraceEnabled()) {
216-
logger.trace("blob url [{}]", uri);
217-
}
198+
logger.trace("blob url [{}]", uri);
218199
String blobpath = uri.getPath().substring(container.length() + 1);
219200
BlobProperties properties = service.getBlobProperties(container, blobpath).getProperties();
220201
String name = blobpath.substring(keyPath.length() + 1);
221-
if (logger.isTraceEnabled()) {
222-
logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getContentLength());
223-
}
202+
logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getContentLength());
224203
blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getContentLength()));
225204
}
226205
}

src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public List<DiscoveryNode> buildDynamicNodes() {
8989
if (refreshInterval.millis() != 0) {
9090
if (cachedDiscoNodes != null &&
9191
(refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
92-
if (logger.isTraceEnabled()) logger.trace("using cache to retrieve node list");
92+
logger.trace("using cache to retrieve node list");
9393
return cachedDiscoNodes;
9494
}
9595
lastRefresh = System.currentTimeMillis();
@@ -106,10 +106,10 @@ public List<DiscoveryNode> buildDynamicNodes() {
106106
if (inetAddress != null) {
107107
ipAddress = inetAddress.getHostAddress();
108108
}
109-
if (logger.isTraceEnabled()) logger.trace("ipAddress found: [{}]", ipAddress);
109+
logger.trace("ipAddress found: [{}]", ipAddress);
110110
} catch (IOException e) {
111111
// We can't find the publish host address... Hmmm. Too bad :-(
112-
if (logger.isTraceEnabled()) logger.trace("exception while finding ipAddress", e);
112+
logger.trace("exception while finding ipAddress", e);
113113
}
114114

115115
try {
@@ -118,10 +118,9 @@ public List<DiscoveryNode> buildDynamicNodes() {
118118
// Let's detect if we want to use public or private IP
119119
if (host_type == HostType.PRIVATE_IP) {
120120
if (instance.getPrivateIp() != null) {
121-
if (logger.isTraceEnabled() && instance.getPrivateIp().equals(ipAddress)) {
121+
if (instance.getPrivateIp().equals(ipAddress)) {
122122
logger.trace("adding ourselves {}", ipAddress);
123123
}
124-
125124
networkAddress = instance.getPrivateIp();
126125
} else {
127126
logger.trace("no private ip provided ignoring {}", instance.getName());

0 commit comments

Comments
 (0)