Skip to content

Commit 1db5234

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

30 files changed

Lines changed: 61 additions & 90 deletions

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public List<OVFPropertyTO> getConfigurableOVFPropertiesFromDocument(Document doc
152152
if (child.getNodeName().equalsIgnoreCase("Category") ||
153153
child.getNodeName().endsWith(":Category")) {
154154
lastCategoryFound = child.getTextContent();
155-
logger.info("Category found " + lastCategoryFound);
155+
logger.info("Category found {}", lastCategoryFound);
156156
} else if (child.getNodeName().equalsIgnoreCase("Property") ||
157157
child.getNodeName().endsWith(":Property")) {
158158
OVFPropertyTO prop = createOVFPropertyFromNode(child, propertyIndex, lastCategoryFound);
@@ -250,13 +250,13 @@ 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());
257257
OVFDisk diskDefinition = getDiskDefinitionFromDiskId(diskId, disks);
258258
if (diskDefinition == null) {
259-
logger.error("Missing disk definition for disk ID " + diskId);
259+
logger.error("Missing disk definition for disk ID {}", diskId);
260260
}
261261
OVFFile fileDefinition = getFileDefinitionFromDiskDefinition(diskDefinition._fileRef, files);
262262
DatadiskTO datadiskTO = generateDiskTO(fileDefinition, diskDefinition, ovfParentPath, diskNumber, diskItem);
@@ -278,7 +278,7 @@ private DatadiskTO generateDiskTO(OVFFile file, OVFDisk disk, String ovfParentPa
278278
if (StringUtils.isNotBlank(path)) {
279279
File f = new File(path);
280280
if (!f.exists() || f.isDirectory()) {
281-
logger.error("One of the attached disk or iso does not exists " + path);
281+
logger.error("One of the attached disk or iso does not exists {}", path);
282282
throw new InternalErrorException("One of the attached disk or iso as stated on OVF does not exists " + path);
283283
}
284284
}
@@ -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 %d file definitions in {}", ()-> vf.size(), () -> ovfFile.getPath());
368368
return vf;
369369
}
370370

@@ -518,9 +518,7 @@ OVFFile getFileDefinitionFromDiskDefinition(String fileRef, List<OVFFile> files)
518518

519519
public List<OVFNetworkTO> getNetPrerequisitesFromDocument(Document doc) throws InternalErrorException {
520520
if (doc == null) {
521-
if (logger.isTraceEnabled()) {
522-
logger.trace("no document to parse; returning no prerequisite networks");
523-
}
521+
logger.trace("no document to parse; returning no prerequisite networks");
524522
return Collections.emptyList();
525523
}
526524

@@ -536,17 +534,15 @@ public List<OVFNetworkTO> getNetPrerequisitesFromDocument(Document doc) throws I
536534
private void matchNicsToNets(Map<String, OVFNetworkTO> nets, Node systemElement) {
537535
final DocumentTraversal traversal = (DocumentTraversal) systemElement;
538536
final NodeIterator iterator = traversal.createNodeIterator(systemElement, NodeFilter.SHOW_ELEMENT, null, true);
539-
logger.trace("starting out with {} network-prerequisites, parsing hardware",nets.size());
537+
logger.trace("starting out with {} network-prerequisites, parsing hardware", () -> nets.size());
540538
int nicCount = 0;
541539
for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
542540
final Element e = (Element) n;
543541
if ("rasd:Connection".equals(e.getTagName())) {
544542
nicCount++;
545543
String name = e.getTextContent(); // should be in our nets
546544
if(nets.get(name) == null) {
547-
if(logger.isInfoEnabled()) {
548-
logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name));
549-
}
545+
logger.info("found a nic definition without a network definition byname {}, adding it to the list.", name);
550546
nets.put(name, new OVFNetworkTO());
551547
}
552548
OVFNetworkTO thisNet = nets.get(name);
@@ -555,7 +551,7 @@ private void matchNicsToNets(Map<String, OVFNetworkTO> nets, Node systemElement)
555551
}
556552
}
557553
}
558-
logger.trace("ending up with %d network-prerequisites, parsed {} nics", nets.size(), nicCount);
554+
logger.trace("ending up with %d network-prerequisites, parsed {} nics", () -> nets.size(), () -> nicCount);
559555
}
560556

561557
/**
@@ -577,7 +573,7 @@ private void fillNicPrerequisites(OVFNetworkTO nic, Node parentNode) {
577573
int addressOnParent = Integer.parseInt(addressOnParentStr);
578574
nic.setAddressOnParent(addressOnParent);
579575
} catch (NumberFormatException e) {
580-
logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: " + addressOnParentStr);
576+
logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: {}", addressOnParentStr);
581577
}
582578

583579
boolean automaticAllocation = StringUtils.isNotBlank(automaticAllocationStr) && Boolean.parseBoolean(automaticAllocationStr);
@@ -589,7 +585,7 @@ private void fillNicPrerequisites(OVFNetworkTO nic, Node parentNode) {
589585
int instanceId = Integer.parseInt(instanceIdStr);
590586
nic.setInstanceID(instanceId);
591587
} catch (NumberFormatException e) {
592-
logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: " + instanceIdStr);
588+
logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: {}", instanceIdStr);
593589
}
594590

595591
nic.setResourceSubType(resourceSubType);
@@ -622,7 +618,7 @@ private Map<String, OVFNetworkTO> getNetworksFromDocumentTree(Document doc) {
622618

623619
nets.put(networkName,network);
624620
}
625-
logger.trace("found {} networks in template", nets.size());
621+
logger.trace("found {} networks in template", () -> nets.size());
626622
return nets;
627623
}
628624

@@ -761,7 +757,7 @@ private Long getLongValueFromString(String value) {
761757
try {
762758
return Long.parseLong(value);
763759
} catch (NumberFormatException e) {
764-
logger.debug("Could not parse the value: " + value + ", ignoring it");
760+
logger.debug("Could not parse the value: {}, ignoring it", value);
765761
}
766762
}
767763
return null;
@@ -772,7 +768,7 @@ private Integer getIntValueFromString(String value) {
772768
try {
773769
return Integer.parseInt(value);
774770
} catch (NumberFormatException e) {
775-
logger.debug("Could not parse the value: " + value + ", ignoring it");
771+
logger.debug("Could not parse the value: {} ignoring it", value);
776772
}
777773
}
778774
return null;
@@ -810,7 +806,7 @@ public List<OVFEulaSectionTO> getEulaSectionsFromDocument(Document doc) {
810806
try {
811807
compressedLicense = compressOVFEula(eulaLicense);
812808
} catch (IOException e) {
813-
logger.error("Could not compress the license for info " + eulaInfo);
809+
logger.error("Could not compress the license for info {}", eulaInfo);
814810
continue;
815811
}
816812
OVFEulaSectionTO eula = new OVFEulaSectionTO(eulaInfo, compressedLicense, eulaIndex);

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 " + ovfFilePath + " " + e.getMessage(), e);
73+
logger.error("Error parsing {} {}", () -> e.getMessage(), () -> e);
7474
return null;
7575
}
7676
}

api/src/main/java/org/apache/cloudstack/acl/RoleType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ public static Long getRoleByAccountType(final Long roleId, final Account.Type ac
105105
* */
106106
public static Account.Type getAccountTypeByRole(final Role role, final Account.Type defautAccountType) {
107107
if (role != null) {
108-
LOGGER.debug(String.format("Role [%s] is not null; therefore, we use its account type [%s].", role, defautAccountType));
108+
LOGGER.debug("Role [{}] is not null; therefore, we use its account type [{}].", role, defautAccountType);
109109
return role.getRoleType().getAccountType();
110110
}
111-
LOGGER.debug(String.format("Role is null; therefore, we use the default account type [%s] value.", defautAccountType));
111+
LOGGER.debug("Role is null; therefore, we use the default account type [{}] value.", defautAccountType);
112112
return defautAccountType;
113113
}
114114
}

api/src/main/java/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public List<Field> getParamFields() {
375375
if (roleIsAllowed) {
376376
validFields.add(field);
377377
} else {
378-
logger.debug("Ignoring parameter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in");
378+
logger.debug("Ignoring parameter {} as the caller is not authorized to pass it in", parameterAnnotation.name());
379379
}
380380
}
381381

api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void execute() {
6161
SuccessResponse response = new SuccessResponse(getCommandName());
6262
this.setResponseObject(response);
6363
} else {
64-
logger.warn("Failed to delete counter with Id: " + getId());
64+
logger.warn("Failed to delete counter with Id: {}", getId());
6565
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete counter.");
6666
}
6767
}

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 " + getStartIp() + " to " + getEndIp() + " of Pod: " + 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=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + 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 " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + 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/AssignVMCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void execute() {
131131
e.printStackTrace();
132132
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
133133
} catch (Exception e) {
134-
logger.error("Failed to move vm due to: " + e.getStackTrace());
134+
logger.error("Failed to move vm due to: {}", e.getStackTrace());
135135
if (e.getMessage() != null) {
136136
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
137137
} else if (e.getCause() != null) {

0 commit comments

Comments
 (0)