Skip to content

Commit 19c10c0

Browse files
authored
Remove string concatenation from logging (#646)
1 parent 577c678 commit 19c10c0

File tree

6 files changed

+96
-119
lines changed

6 files changed

+96
-119
lines changed

src/main/java/io/jenkins/plugins/pipelinegraphview/consoleview/PipelineConsoleViewAction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public HttpResponse getSteps(StaplerRequest2 req) throws IOException {
8282
}
8383

8484
private JSONObject getSteps(String nodeId) throws IOException {
85-
logger.debug("getSteps was passed nodeId '" + nodeId + "'.");
85+
logger.debug("getSteps was passed nodeId '{}'.", nodeId);
8686
PipelineStepList steps = stepApi.getSteps(nodeId);
8787
String stepsJson = MAPPER.writeValueAsString(steps);
8888
if (logger.isDebugEnabled()) {
89-
logger.debug("Steps: '" + stepsJson + "'.");
89+
logger.debug("Steps for {}: '{}'.", nodeId, stepsJson);
9090
}
9191
return JSONObject.fromObject(stepsJson);
9292
}
@@ -105,7 +105,7 @@ protected JSONObject getAllSteps() throws IOException {
105105
PipelineStepList steps = stepApi.getAllSteps();
106106
String stepsJson = MAPPER.writeValueAsString(steps);
107107
if (logger.isDebugEnabled()) {
108-
logger.debug("Steps: '" + stepsJson + "'.");
108+
logger.debug("Steps: '{}'.", stepsJson);
109109
}
110110
return JSONObject.fromObject(stepsJson);
111111
}
@@ -117,7 +117,7 @@ public HttpResponse getConsoleText(StaplerRequest2 req, StaplerResponse2 rsp) th
117117
logger.error("'consoleText' was not passed 'nodeId'.");
118118
return HttpResponses.errorJSON("Error getting console text");
119119
}
120-
logger.debug("getConsoleText was passed node id '" + nodeId + "'.");
120+
logger.debug("getConsoleText was passed node id '{}'.", nodeId);
121121
// This will be a step, so return its log output.
122122
AnnotatedLargeText<? extends FlowNode> logText = getLogForNode(nodeId);
123123

@@ -165,7 +165,7 @@ public HttpResponse getConsoleOutput(StaplerRequest2 req) throws IOException {
165165
logger.error("'consoleJson' was not passed 'nodeId'.");
166166
return HttpResponses.errorJSON("Error getting console json");
167167
}
168-
logger.debug("getConsoleOutput was passed node id '" + nodeId + "'.");
168+
logger.debug("getConsoleOutput was passed node id '{}'.", nodeId);
169169
// This will be a step, so return it's log output.
170170
// startByte to start getting data from. If negative will startByte from end of string with
171171
// LOG_THRESHOLD.
@@ -194,18 +194,18 @@ protected JSONObject getConsoleOutputJson(String nodeId, Long requestStartByte)
194194
}
195195
// if startByte is negative make sure we don't try and get a byte before 0.
196196
if (requestStartByte < 0L) {
197-
logger.debug("consoleJson - requested negative startByte '" + requestStartByte + "'.");
197+
logger.debug("consoleJson - requested negative startByte '{}'.", requestStartByte);
198198
startByte = textLength + requestStartByte;
199199
if (startByte < 0L) {
200-
logger.debug("consoleJson - requested negative startByte '"
201-
+ requestStartByte
202-
+ "' out of bounds, starting at 0.");
200+
logger.debug(
201+
"consoleJson - requested negative startByte '{}' out of bounds, starting at 0.",
202+
requestStartByte);
203203
startByte = 0L;
204204
}
205205
} else {
206206
startByte = requestStartByte;
207207
}
208-
logger.debug("Returning '" + (textLength - startByte) + "' bytes from 'getConsoleOutput'.");
208+
logger.debug("Returning '{}' bytes from 'getConsoleOutput'.", textLength - startByte);
209209
text = PipelineNodeUtil.convertLogToString(logText, startByte, true);
210210
endByte = textLength;
211211
}
@@ -254,10 +254,10 @@ private boolean isUnhandledException(String nodeId) throws IOException {
254254

255255
private static long parseIntWithDefault(String s, long defaultValue) {
256256
try {
257-
logger.debug("Parsing user provided value of '" + s + "'");
257+
logger.debug("Parsing user provided value of '{}'", s);
258258
return Long.parseLong(s);
259259
} catch (NumberFormatException e) {
260-
logger.debug("Using default value of '" + defaultValue + "'");
260+
logger.debug("Using default value of '{}'", defaultValue);
261261
return defaultValue;
262262
}
263263
}

src/main/java/io/jenkins/plugins/pipelinegraphview/treescanner/PipelineNodeTreeScanner.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ private void buildGraph() {
397397
}
398398
return (BlockEndNode<?>) node;
399399
}
400-
logger.error(String.format(
401-
"Could not find BlockEndNode that threw exception:{}.", errorAction.getDisplayName()));
400+
logger.error("Could not find BlockEndNode that threw exception:{}.", errorAction.getDisplayName());
402401
}
403402
return null;
404403
}
@@ -431,9 +430,10 @@ private void handleException(
431430
private void assignParent(@NonNull FlowNodeWrapper wrappedNode, @CheckForNull FlowNode parent) {
432431
if (parent != null) {
433432
if (!wrappedNodeMap.containsKey(parent.getId())) {
434-
logger.error(String.format(
435-
"Couldn't find start of node %s (parent of %s) in wrappedNodeMap.",
436-
parent.getId(), wrappedNode.getId()));
433+
logger.error(
434+
"Couldn't find start of node {} (parent of {}) in wrappedNodeMap.",
435+
parent.getId(),
436+
wrappedNode.getId());
437437
} else {
438438
FlowNodeWrapper wrappedParent = wrappedNodeMap.get(parent.getId());
439439
assignParent(wrappedNode, wrappedParent);

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApi.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ private PipelineGraph createShallowTree(PipelineGraphBuilderApi builder) {
190190
topLevelStageIds.add(stage.getId());
191191
}
192192
} catch (IOException ex) {
193-
logger.error("Caught a "
194-
+ ex.getClass().getSimpleName()
195-
+ " when trying to find parent of stage '"
196-
+ stage.getName()
197-
+ "'");
193+
logger.error(
194+
"Caught a {} when trying to find parent of stage '{}'",
195+
ex.getClass().getSimpleName(),
196+
stage.getName());
198197
}
199198
});
200199

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStepApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public PipelineStepApi(WorkflowRun run) {
1919

2020
private List<PipelineStep> parseSteps(List<FlowNodeWrapper> stepNodes, String stageId) {
2121
if (logger.isDebugEnabled()) {
22-
logger.debug("PipelineStepApi steps: '" + stepNodes + "'.");
22+
logger.debug("PipelineStepApi steps: '{}'.", stepNodes);
2323
}
2424
List<PipelineStep> steps = stepNodes.stream()
2525
.map(flowNodeWrapper -> {
@@ -41,9 +41,9 @@ private List<PipelineStep> parseSteps(List<FlowNodeWrapper> stepNodes, String st
4141
}
4242
}
4343
// Remove non-printable chars (e.g. ANSI color codes).
44-
logger.debug("DisplayName Before: '" + displayName + "'.");
44+
logger.debug("DisplayName Before: '{}'.", displayName);
4545
displayName = cleanTextContent(displayName);
46-
logger.debug("DisplayName After: '" + displayName + "'.");
46+
logger.debug("DisplayName After: '{}'.", displayName);
4747

4848
// Ignore certain titles
4949
if (!displayName.isBlank()) {

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/legacy/PipelineNodeGraphVisitor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ public PipelineNodeGraphVisitor(WorkflowRun run) {
125125
// Log run ID, because the eventual exception handler (probably Stapler) isn't
126126
// specific
127127
// enough to do so
128-
logger.error("Caught a "
129-
+ t.getClass().getSimpleName()
130-
+ " traversing the graph for run "
131-
+ run.getExternalizableId());
128+
logger.error(
129+
"Caught a {} traversing the graph for run {}",
130+
t.getClass().getSimpleName(),
131+
run.getExternalizableId());
132132
throw t;
133133
}
134134
} else {
135-
logger.debug("Could not find execution for run " + run.getExternalizableId());
135+
logger.debug("Could not find execution for run {}", run.getExternalizableId());
136136
}
137137
}
138138

@@ -369,9 +369,10 @@ public void parallelStart(
369369
}
370370

371371
if (nestedbranches.size() != parallelBranchEndNodes.size()) {
372-
logger.debug(String.format(
373-
"nestedBranches size: %s not equal to parallelBranchEndNodes: %s",
374-
nestedbranches.size(), parallelBranchEndNodes.size()));
372+
logger.debug(
373+
"nestedBranches size: {} not equal to parallelBranchEndNodes: {}",
374+
nestedbranches.size(),
375+
parallelBranchEndNodes.size());
375376
if (!parallelEnds.isEmpty()) {
376377
parallelEnds.pop();
377378
}
@@ -662,7 +663,7 @@ public void atomNode(
662663
}
663664

664665
private void dump(String str) {
665-
logger.debug(System.identityHashCode(this) + ": " + str);
666+
logger.debug("{}: {}", System.identityHashCode(this), str);
666667
}
667668

668669
/**

0 commit comments

Comments
 (0)