Skip to content

Commit 5ccbe3f

Browse files
author
klaus.freitas.scclouds
committed
Refactor cloud-agent module logs for Log4j2
1 parent e44c17e commit 5ccbe3f

5 files changed

Lines changed: 21 additions & 34 deletions

File tree

agent/src/main/java/com/cloud/agent/Agent.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,9 +1192,8 @@ protected void runInContext() {
11921192
shell.launchNewAgent(resource);
11931193
return;
11941194
}
1195-
if (logger.isTraceEnabled()) {
1196-
logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds");
1197-
}
1195+
logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds");
1196+
11981197
Thread.sleep(5000);
11991198
} catch (final Exception e) {
12001199
logger.warn("Failed to execute post certificate renewal command:", e);
@@ -1215,23 +1214,20 @@ protected void runInContext() {
12151214
}
12161215
final String preferredHost = msList[0];
12171216
final String connectedHost = _shell.getConnectedHost();
1218-
if (logger.isTraceEnabled()) {
1219-
logger.trace("Running preferred host checker task, connected host=" + connectedHost + ", preferred host=" + preferredHost);
1220-
}
1217+
logger.trace("Running preferred host checker task, connected host=" + connectedHost + ", preferred host=" + preferredHost);
1218+
12211219
if (preferredHost != null && !preferredHost.equals(connectedHost) && _link != null) {
12221220
boolean isHostUp = true;
12231221
try (final Socket socket = new Socket()) {
12241222
socket.connect(new InetSocketAddress(preferredHost, _shell.getPort()), 5000);
12251223
} catch (final IOException e) {
12261224
isHostUp = false;
1227-
if (logger.isTraceEnabled()) {
1228-
logger.trace("Host: " + preferredHost + " is not reachable");
1229-
}
1225+
logger.trace("Host: " + preferredHost + " is not reachable");
1226+
12301227
}
12311228
if (isHostUp && _link != null && _inProgress.get() == 0) {
1232-
if (logger.isDebugEnabled()) {
1233-
logger.debug("Preferred host " + preferredHost + " is found to be reachable, trying to reconnect");
1234-
}
1229+
logger.debug("Preferred host " + preferredHost + " is found to be reachable, trying to reconnect");
1230+
12351231
_shell.resetHostCounter();
12361232
reconnect(_link);
12371233
}

agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ public synchronized boolean configure(String name, Map<String, Object> params) {
9393
file = new File(path);
9494
try {
9595
if (!file.createNewFile()) {
96-
logger.error(String.format("Unable to create _file: %s", file.getAbsolutePath()));
96+
logger.error("Unable to create _file: {}", file.getAbsolutePath());
9797
return false;
9898
}
9999
} catch (IOException e) {
100-
logger.error(String.format("Unable to create file: %s", file.getAbsolutePath()));
101-
if (logger.isDebugEnabled()) {
102-
logger.debug(String.format("IOException while trying to create file: %s", file.getAbsolutePath()), e);
103-
}
100+
logger.error("Unable to create file: {}", file.getAbsolutePath());
101+
logger.debug("IOException while trying to create file: {}", file.getAbsolutePath(), e);
104102
return false;
105103
}
106104
}

agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public String startVM(String vmName, String vnetId, String gateway, String dns,
8787

8888
@Override
8989
public String stopVM(String vmName, boolean force) {
90-
if (logger.isInfoEnabled())
91-
logger.info("Stop VM. name: " + vmName);
90+
logger.info("Stop VM. name: " + vmName);
9291

9392
synchronized (this) {
9493
MockVm vm = vms.get(vmName);
@@ -103,8 +102,7 @@ public String stopVM(String vmName, boolean force) {
103102

104103
@Override
105104
public String rebootVM(String vmName) {
106-
if (logger.isInfoEnabled())
107-
logger.info("Reboot VM. name: " + vmName);
105+
logger.info("Reboot VM. name: " + vmName);
108106

109107
synchronized (this) {
110108
MockVm vm = vms.get(vmName);
@@ -116,8 +114,7 @@ public String rebootVM(String vmName) {
116114

117115
@Override
118116
public boolean migrate(String vmName, String params) {
119-
if (logger.isInfoEnabled())
120-
logger.info("Migrate VM. name: " + vmName);
117+
logger.info("Migrate VM. name: " + vmName);
121118

122119
synchronized (this) {
123120
MockVm vm = vms.get(vmName);

agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public static <T> T getPropertyValue(AgentProperties.Property<T> property) {
4848
File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE);
4949

5050
if (agentPropertiesFile == null) {
51-
LOGGER.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue));
51+
LOGGER.debug("File [{}] was not found, we will use default defined values. Property [{}]: [{}].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue);
5252

5353
return defaultValue;
5454
}
5555

5656
try {
5757
String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
5858
if (StringUtils.isBlank(configValue)) {
59-
LOGGER.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue));
59+
LOGGER.debug("Property [{}] has empty or null value. Using default value [{}].", name, defaultValue);
6060
return defaultValue;
6161
}
6262

@@ -68,11 +68,11 @@ public static <T> T getPropertyValue(AgentProperties.Property<T> property) {
6868
ConvertUtils.register(new LongConverter(defaultValue), Long.class);
6969
}
7070

71-
LOGGER.debug(String.format("Property [%s] was altered. Now using the value [%s].", name, configValue));
71+
LOGGER.debug("Property [{}] was altered. Now using the value [{}].", name, configValue);
7272
return (T)ConvertUtils.convert(configValue, property.getTypeClass());
7373

7474
} catch (IOException ex) {
75-
LOGGER.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex);
75+
LOGGER.debug("Failed to get property [{}]. Using default value [{}].", name, defaultValue, ex);
7676
}
7777

7878
return defaultValue;

agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
278278
disableRpFilter();
279279
}
280280

281-
if (logger.isInfoEnabled())
282-
logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId);
281+
logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId);
283282

284283
return true;
285284
}
@@ -431,18 +430,15 @@ public void reportLoadInfo(String gsonLoadInfo) {
431430
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(proxyVmId, gsonLoadInfo);
432431
try {
433432
getAgentControl().postRequest(cmd);
434-
435-
if (logger.isDebugEnabled())
436-
logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo);
433+
logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo);
437434
} catch (AgentControlChannelException e) {
438435
logger.error("Unable to send out load info due to " + e.getMessage(), e);
439436
}
440437
}
441438

442439
public void ensureRoute(String address) {
443440
if (localGateway != null) {
444-
if (logger.isDebugEnabled())
445-
logger.debug("Ensure route for " + address + " via " + localGateway);
441+
logger.debug("Ensure route for " + address + " via " + localGateway);
446442

447443
// this method won't be called in high frequency, serialize access
448444
// to script execution

0 commit comments

Comments
 (0)