Skip to content

Commit

Permalink
Fix various logging String.format issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwowen committed Aug 3, 2024
1 parent 9e7ddeb commit 08f04cb
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public int compare(BuildTagBean o1, BuildTagBean o2) {
if (tagBuild.getScm_commit().equals(build.getScm_commit())) {
// Tag is on the exact commit
LOG.debug(
"Found tag on the exact commit {}",
"Found tag {} on the exact commit {}",
tags.get(i).getTag().getValue(),
tagBuild.getScm_commit());
ret = tags.get(i).getTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void transition(DeployBean deployBean, DeployBean newDeployBean, EnvironBean env
if (oldState != DeployState.RUNNING) {
LOG.info("Set deploy {} from {} to RUNNING.", deployId, oldState);
} else {
LOG.debug("Deploy {} is still RUNNING...", deployId, oldState);
LOG.debug("Deploy {} is still RUNNING...", deployId);
}
newDeployBean.setState(DeployState.RUNNING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private void emitMetrics(AgentBean updateBean) {
String.valueOf(updateBean.getStatus().equals(AgentStatus.SUCCEEDED)))
.increment();
} catch (Exception ex) {
LOG.warn("Failed to emit metrics of {}", updateBean.toString(), ex);
LOG.warn("Failed to emit metrics of {}", updateBean, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ boolean canDeployWithConstraint(String hostId, EnvironBean envBean) throws Excep
hostId,
totalActiveAgentsWithHostTag,
maxParallelWithHostTag,
deployConstraintBean.toString());
deployConstraintBean);
return false;
}
if (deployConstraintBean.getConstraint_type() == DeployConstraintType.GROUP_BY_GROUP) {
Expand Down Expand Up @@ -601,7 +601,7 @@ boolean canDeploywithSchedule(EnvironBean env) throws Exception {

if (schedule.getState() == ScheduleState.COOLING_DOWN) {
LOG.debug(
"Env {} is currently cooling down. Host {} will wait until the cooling down period is over.",
"Env {} is currently cooling down. Hosts will wait until the cooling down period is over.",
env.getEnv_id());
return false;
} else {
Expand Down Expand Up @@ -707,7 +707,7 @@ Map<String, PingReportBean> convertReports(PingRequestBean pingRequest) {
PingRequestBean normalizePingRequest(PingRequestBean pingRequest) throws Exception {
String hostId = pingRequest.getHostId();
if (StringUtils.isEmpty(hostId)) {
LOG.error("Missing host id in request: ", pingRequest);
LOG.error("Missing host id in request: {}", pingRequest);
throw new DeployInternalException("Missing host id in PingReqest");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void validate(PingRequestBean bean, Set<String> accountAllowList) throws
if (!StringUtils.startsWith(bean.getHostId(), "i-")) {
LOG.warn("Ignore invalid id {} for host {}", bean.getHostId(), bean.getHostName());
throw new DeployInternalException(
String.format("Host id {} is not a valid ec2 instance id"),
String.format("Host id %s is not a valid ec2 instance id", bean.getHostId()),
StringUtils.defaultString(bean.getHostId()));
}

Expand All @@ -53,7 +53,9 @@ public void validate(PingRequestBean bean, Set<String> accountAllowList) throws
bean.getHostName(),
accountId);
throw new DeployInternalException(
String.format("Host id {} is from an disallowed AWS account: {}"),
String.format(
"Host id %s is from an disallowed AWS account: %s",
bean.getHostId(), accountId),
StringUtils.defaultString(bean.getHostId()),
accountId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private SourceControlManager getSourceControlManager(String scmType) throws Exce
}
SourceControlManager manager = this.managers.get(scmType);
if (manager == null) {
LOG.error("Unsupported SCM type: " + scmType);
LOG.error("Unsupported SCM type: {}", scmType);
throw new Exception("Unsupported SCM type: " + scmType);
}
return manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ public Response alertsTriggered(
return Response.status(400).build();
}

LOG.info(
"Get Alert triggered: {} time:{}",
alert.isTriggered(),
alert.getTriggeredDate().toString());
LOG.info("Get Alert triggered: {} time:{}", alert.isTriggered(), alert.getTriggeredDate());

if (!alert.isTriggered()) {
LOG.info("No action for alert off");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ public Response create(
String operator = sc.getUserPrincipal().getName();
TagBean retEntity = new TagBean();
if (handlers.containsKey(tag.getTarget_type())) {
LOG.debug("Found handler for target type {}", tag.getTarget_type().toString());
LOG.debug("Found handler for target type {}", tag.getTarget_type());
retEntity = handlers.get(tag.getTarget_type()).createTag(tag, operator);
} else {
LOG.debug(
"No handler found for target type {}. Use default",
tag.getTarget_type().toString());
LOG.debug("No handler found for target type {}. Use default", tag.getTarget_type());
// Default logic. Ideally each type should write its own handler.
// At current time, ignore the target id object existence test. The
// handler should do that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public <E> E getScheduledCheckResult(
LOG.info(
"Auto deploy due time is {} for check time {} for Environment {}",
autoDeployDueDate.toString(ISODateTimeFormat.dateTime()),
checkTime.toString(),
checkTime,
currEnvBean.getEnv_name());

if (!autoDeployDueDate.isAfterNow()) {
Expand Down Expand Up @@ -310,10 +310,7 @@ public void promoteBuild(

PromoteResult result =
computePromoteBuildResult(currEnvBean, currDeployBean, size, promoteBean);
LOG.info(
"Promote result {} for env {}",
result.getResult().toString(),
currEnvBean.getEnv_name());
LOG.info("Promote result {} for env {}", result.getResult(), currEnvBean.getEnv_name());
if (result.getResult() == PromoteResult.ResultCode.PromoteBuild
&& StringUtils.isNotEmpty(result.getPromotedBuild())) {
safePromote(
Expand Down Expand Up @@ -407,10 +404,7 @@ DeployBean promoteDeploy(
throws Exception {
PromoteResult result =
computePromoteDeployResult(currEnvBean, currDeployBean, size, promoteBean);
LOG.info(
"Promote result {} for env {}",
result.getResult().toString(),
currEnvBean.getEnv_name());
LOG.info("Promote result {} for env {}", result.getResult(), currEnvBean.getEnv_name());
if (result.getResult() == PromoteResult.ResultCode.PromoteDeploy
&& result.getPredDeployInfo() != null) {
safePromote(
Expand Down Expand Up @@ -533,8 +527,8 @@ List<BuildBean> getBuildCandidates(EnvironBean envBean, Interval interval, int s
availableBuilds.size(),
buildName,
scmBranch,
interval.getStart().toString(),
interval.getEnd().toString());
interval.getStart(),
interval.getEnd());
if (!availableBuilds.isEmpty()) {
List<BuildTagBean> buildTagBeanList =
buildTagsManager.getEffectiveTagsWithBuilds(availableBuilds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ private void processBatch() throws Exception {
} catch (SQLException e) {
LOG.error(
"failed to process job due to SQLException: {} Error {} stack {}",
job.toString(),
job,
ExceptionUtils.getRootCauseMessage(e),
ExceptionUtils.getStackTrace(e));

errorBudgetFailure.increment();
} catch (Exception e) {
LOG.error(
"failed to process job due to all other exceptions: {} Error {} stack {}",
job.toString(),
job,
ExceptionUtils.getRootCauseMessage(e),
ExceptionUtils.getStackTrace(e));
job.setState(TagSyncState.ERROR);
LOG.error(
"job {} deploy constraint transitions to error state due to exceptions",
job.toString());
job);
LOG.info("updated job state to {}", TagSyncState.ERROR);
deployConstraintDAO.updateById(job.getConstraint_id(), job);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private boolean removeTerminatedHost(HostBean host) throws Exception {
Collection<String> terminatedHosts =
rodimusManager.getTerminatedHosts(Collections.singletonList(hostId));
if (terminatedHosts.contains(hostId)) {
LOG.info(String.format("Delete records of terminated host {}", hostId));
LOG.info("Delete records of terminated host {}", hostId);
hostHandler.removeHost(hostId);
return true;
}
Expand All @@ -127,10 +127,7 @@ private void processBatch() throws Exception {
}
} catch (Exception e) {
LOG.error(
"Failed to process {} host {}",
host.getState().toString(),
host.getHost_id(),
e);
"Failed to process {} host {}", host.getState(), host.getHost_id(), e);
} finally {
utilDAO.releaseLock(lockName, connection);
LOG.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void processAllHosts() throws Exception {
}
if (!maxStaleHostIds.isEmpty()) {
LOG.info(
"Found the following hosts (Explicit capacity) exceeded maxStaleThreshold: ",
"Found the following hosts (Explicit capacity) exceeded maxStaleThreshold: {}",
maxStaleHostIds);
processStaleHosts(maxStaleHostIds, true);
}
Expand All @@ -113,7 +113,7 @@ void processAllHosts() throws Exception {
}
if (!minStaleHostIds.isEmpty()) {
LOG.info(
"Found following hosts (Explicit capacity) exceeded minStaleThreshold: ",
"Found following hosts (Explicit capacity) exceeded minStaleThreshold: {}",
minStaleHostIds);
processStaleHosts(minStaleHostIds, false);
}
Expand Down

0 comments on commit 08f04cb

Please sign in to comment.