Skip to content

Commit 3ea0aa3

Browse files
author
klaus.freitas.scclouds
committed
more log refactoring
1 parent 1db5234 commit 3ea0aa3

13 files changed

Lines changed: 25 additions & 25 deletions

api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import org.apache.cloudstack.utils.security.ParserUtils;
3939
import org.apache.commons.collections.CollectionUtils;
40+
import org.apache.commons.lang.ObjectUtils;
4041
import org.apache.commons.lang.math.NumberUtils;
4142
import org.apache.commons.lang3.StringUtils;
4243
import org.apache.logging.log4j.Logger;
@@ -119,8 +120,7 @@ protected OVFPropertyTO createOVFPropertyFromNode(Node node, int index, String c
119120
boolean password = StringUtils.isNotBlank(passStr) && passStr.equalsIgnoreCase("true");
120121
String label = ovfParser.getChildNodeValue(node, "Label");
121122
String description = ovfParser.getChildNodeValue(node, "Description");
122-
logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category)
123-
+ " with key = " + key);
123+
logger.debug("Creating OVF property index {} with key = {}", ObjectUtils.defaultIfNull(index + " for category" + category, index), key);
124124
return new OVFPropertyTO(key, type, value, qualifiers, userConfigurable,
125125
label, description, password, index, category);
126126
}
@@ -250,7 +250,7 @@ private List<DatadiskTO> matchHardwareItemsToDiskAndFilesInformation(List<OVFVir
250250
int diskNumber = 0;
251251
for (OVFVirtualHardwareItemTO diskItem : diskHardwareItems) {
252252
if (StringUtils.isBlank(diskItem.getHostResource())) {
253-
logger.error("Missing disk information for hardware item {} {}", () -> diskItem.getElementName(), () -> diskItem.getInstanceId());
253+
logger.error("Missing disk information for hardware item {} {}", diskItem.getElementName(), diskItem.getInstanceId());
254254
continue;
255255
}
256256
String diskId = extractDiskIdFromDiskHostResource(diskItem.getHostResource());
@@ -334,7 +334,7 @@ protected List<OVFDisk> extractDisksFromOvfDocumentTree(Document doc) {
334334
od._controller = getControllerType(items, od._diskId);
335335
vd.add(od);
336336
}
337-
logger.trace("found {} disk definitions", () -> vd.size());
337+
logger.trace("Found {} disk definitions", vd.size());
338338
return vd;
339339
}
340340

@@ -364,7 +364,7 @@ protected List<OVFFile> extractFilesFromOvfDocumentTree(File ovfFile, Document d
364364
vf.add(of);
365365
}
366366
}
367-
logger.trace("found %d file definitions in {}", ()-> vf.size(), () -> ovfFile.getPath());
367+
logger.trace("Found {} file definitions in {}", vf.size(), ovfFile.getPath());
368368
return vf;
369369
}
370370

@@ -502,7 +502,7 @@ private void writeDocumentToFile(String newOvfFilePath, Document doc) {
502502
outfile.write(writer.toString());
503503
outfile.close();
504504
} catch (IOException | TransformerException e) {
505-
logger.info("Unexpected exception caught while rewriting OVF:" + e.getMessage(), e);
505+
logger.info("Unexpected exception caught while rewriting OVF:{}", e.getMessage(), e);
506506
throw new CloudRuntimeException(e);
507507
}
508508
}
@@ -518,7 +518,7 @@ OVFFile getFileDefinitionFromDiskDefinition(String fileRef, List<OVFFile> files)
518518

519519
public List<OVFNetworkTO> getNetPrerequisitesFromDocument(Document doc) throws InternalErrorException {
520520
if (doc == null) {
521-
logger.trace("no document to parse; returning no prerequisite networks");
521+
logger.trace("No document to parse; returning no prerequisite networks");
522522
return Collections.emptyList();
523523
}
524524

@@ -534,15 +534,15 @@ public List<OVFNetworkTO> getNetPrerequisitesFromDocument(Document doc) throws I
534534
private void matchNicsToNets(Map<String, OVFNetworkTO> nets, Node systemElement) {
535535
final DocumentTraversal traversal = (DocumentTraversal) systemElement;
536536
final NodeIterator iterator = traversal.createNodeIterator(systemElement, NodeFilter.SHOW_ELEMENT, null, true);
537-
logger.trace("starting out with {} network-prerequisites, parsing hardware", () -> nets.size());
537+
logger.trace("Starting out with {} network-prerequisites, parsing hardware", nets.size());
538538
int nicCount = 0;
539539
for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
540540
final Element e = (Element) n;
541541
if ("rasd:Connection".equals(e.getTagName())) {
542542
nicCount++;
543543
String name = e.getTextContent(); // should be in our nets
544544
if(nets.get(name) == null) {
545-
logger.info("found a nic definition without a network definition byname {}, adding it to the list.", name);
545+
logger.info("Found a nic definition without a network definition byname {}, adding it to the list.", name);
546546
nets.put(name, new OVFNetworkTO());
547547
}
548548
OVFNetworkTO thisNet = nets.get(name);
@@ -551,7 +551,7 @@ private void matchNicsToNets(Map<String, OVFNetworkTO> nets, Node systemElement)
551551
}
552552
}
553553
}
554-
logger.trace("ending up with %d network-prerequisites, parsed {} nics", () -> nets.size(), () -> nicCount);
554+
logger.trace("Ending up with {} network-prerequisites, parsed {} nics", nets.size(), nicCount);
555555
}
556556

557557
/**
@@ -618,7 +618,7 @@ private Map<String, OVFNetworkTO> getNetworksFromDocumentTree(Document doc) {
618618

619619
nets.put(networkName,network);
620620
}
621-
logger.trace("found {} networks in template", () -> nets.size());
621+
logger.trace("Found {} networks in template", nets.size());
622622
return nets;
623623
}
624624

api/src/main/java/com/cloud/agent/api/storage/OVFParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public OVFParser() {
5454
documentBuilderFactory.setNamespaceAware(true);
5555
documentBuilder = documentBuilderFactory.newDocumentBuilder();
5656
} catch (ParserConfigurationException e) {
57-
logger.error("Cannot start the OVF parser: {}", () -> e.getMessage(), () -> e);
57+
logger.error("Cannot start the OVF parser: {}", e.getMessage(), e);
5858
}
5959
}
6060

@@ -70,7 +70,7 @@ public Document parseOVFFile(String ovfFilePath) {
7070
try {
7171
return documentBuilder.parse(new File(ovfFilePath));
7272
} catch (SAXException | IOException e) {
73-
logger.error("Error parsing {} {}", () -> e.getMessage(), () -> e);
73+
logger.error("Error parsing {} {}", e.getMessage(), e);
7474
return null;
7575
}
7676
}

api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void execute() {
9898
this.setResponseObject(response);
9999
} catch (CloudRuntimeException e) {
100100
ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
101-
logger.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e);
101+
logger.error("Failed to update Backup Offering [id: {}] due to: [{}].", id, e.getMessage(), e);
102102
throw new ServerApiException(paramError, e.getMessage());
103103
}
104104
}

api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void execute() {
9595
}
9696

9797
try {
98-
logger.debug("Uploading certificate " + name + " to agents for Direct Download");
98+
logger.debug("Uploading certificate {} to agents for Direct Download", name);
9999
Pair<DirectDownloadCertificate, List<HostCertificateStatus>> uploadStatus =
100100
directDownloadManager.uploadCertificateToHosts(certificate, name, hypervisor, zoneId, hostId);
101101
DirectDownloadCertificate certificate = uploadStatus.first();

api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void execute() {
125125
hostResponse.setResponseName(getCommandName());
126126
this.setResponseObject(hostResponse);
127127
} catch (Exception e) {
128-
logger.debug("Failed to update host:" + getId(), e);
128+
logger.debug("Failed to update host:{}", getId(), e);
129129
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage());
130130
}
131131
}

api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void execute() {
116116
logger.warn("Exception: ", ex);
117117
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
118118
} catch (Exception e) {
119-
logger.warn("Failed to delete management ip range from {} to {} of Pod: {}", () -> getStartIp(), () -> getEndIp(), () -> getPodId(), () -> e);
119+
logger.warn("Failed to delete management ip range from {} to {} of Pod: {}", getStartIp(), getEndIp(), getPodId(), e);
120120
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
121121
}
122122
}

api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
7575
SuccessResponse response = new SuccessResponse(getCommandName());
7676
this.setResponseObject(response);
7777
} catch (Exception e) {
78-
logger.warn("Failed to delete storage network ip range {}", () -> getId(), () -> e);
78+
logger.warn("Failed to delete storage network ip range {}", getId(), e);
7979
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
8080
}
8181
}

api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
9797
response.setResponseName(getCommandName());
9898
this.setResponseObject(response);
9999
} catch (Exception e) {
100-
logger.warn("Failed to list storage network ip range for rangeId={} podId={} zoneId={}", () -> getRangeId(), () -> getPodId(), () -> getZoneId());
100+
logger.warn("Failed to list storage network ip range for rangeId={} podId={} zoneId={}", getRangeId(), getPodId(), getZoneId());
101101
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
102102
}
103103
}

api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void execute() {
139139
logger.warn("Exception: ", ex);
140140
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
141141
} catch (Exception e) {
142-
logger.warn("Failed to update pod management IP range {}-{} of Pod: {}", () -> getNewStartIP(), () -> getNewEndIP(), () -> getPodId(), () -> e);
142+
logger.warn("Failed to update pod management IP range {}-{} of Pod: {}", getNewStartIP(), getNewEndIP(), getPodId(), e);
143143
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
144144
}
145145
}

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public Map<String, Long> getNicNetworkList() {
201201
for (Map<String, String> entry : (Collection<Map<String, String>>)nicNetworkList.values()) {
202202
String nic = entry.get(VmDetailConstants.NIC);
203203
String networkUuid = entry.get(VmDetailConstants.NETWORK);
204-
logger.trace(String.format("nic, '{}', goes on net, '{}'", nic, networkUuid));
204+
logger.trace("nic, '{}', goes on net, '{}'", nic, networkUuid);
205205
if (StringUtils.isAnyEmpty(nic, networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) {
206206
throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic));
207207
}
@@ -217,7 +217,7 @@ public Map<String, Network.IpAddresses> getNicIpAddressList() {
217217
for (Map<String, String> entry : (Collection<Map<String, String>>)nicIpAddressList.values()) {
218218
String nic = entry.get(VmDetailConstants.NIC);
219219
String ipAddress = StringUtils.defaultIfEmpty(entry.get(VmDetailConstants.IP4_ADDRESS), null);
220-
logger.trace(String.format("nic, '{}', gets ip, '{}'", nic, ipAddress));
220+
logger.trace("nic, '{}', gets ip, '{}'", nic, ipAddress);
221221
if (StringUtils.isEmpty(nic)) {
222222
throw new InvalidParameterValueException(String.format("NIC ID: '%s' is invalid for IP address mapping", nic));
223223
}

0 commit comments

Comments
 (0)