Skip to content

Commit cabb73b

Browse files
openrewrite: apply Slf4jBestPractices
This fixes some practice not all of which easy to notice manually, notably use SLF4J parameters instead of string concatenation. ```bash ./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-logging-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.logging.slf4j.Slf4jBestPractices ``` Signed-off-by: Adrian Cole <[email protected]>
1 parent e7d5753 commit cabb73b

File tree

15 files changed

+23
-30
lines changed

15 files changed

+23
-30
lines changed

examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
System.out.println("----- " + namespace + " -----");
7474
getNamespacedPod(namespace).stream().forEach(System.out::println);
7575
} catch (ApiException ex) {
76-
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
76+
LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex);
7777
}
7878
});
7979

@@ -242,7 +242,7 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
242242
appsV1Api.replaceNamespacedDeployment(
243243
deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null);
244244
} catch (ApiException ex) {
245-
LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
245+
LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex);
246246
}
247247
});
248248
}

examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
System.out.println("----- " + namespace + " -----");
7474
getNamespacedPod(namespace).stream().forEach(System.out::println);
7575
} catch (ApiException ex) {
76-
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
76+
LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex);
7777
}
7878
});
7979

@@ -242,7 +242,7 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
242242
appsV1Api.replaceNamespacedDeployment(
243243
deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null);
244244
} catch (ApiException ex) {
245-
LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
245+
LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex);
246246
}
247247
});
248248
}

examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
System.out.println("----- " + namespace + " -----");
7474
getNamespacedPod(namespace).stream().forEach(System.out::println);
7575
} catch (ApiException ex) {
76-
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
76+
LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex);
7777
}
7878
});
7979

@@ -245,7 +245,7 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
245245
appsV1Api.replaceNamespacedDeployment(
246246
deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null);
247247
} catch (ApiException ex) {
248-
LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
248+
LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex);
249249
}
250250
});
251251
}

examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
System.out.println("----- " + namespace + " -----");
7474
getNamespacedPod(namespace).stream().forEach(System.out::println);
7575
} catch (ApiException ex) {
76-
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
76+
LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex);
7777
}
7878
});
7979

@@ -218,7 +218,7 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
218218
appsV1Api.replaceNamespacedDeployment(
219219
deploymentName, DEFAULT_NAME_SPACE, newDeploy).execute();
220220
} catch (ApiException ex) {
221-
LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
221+
LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex);
222222
}
223223
});
224224
}

examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
System.out.println("----- " + namespace + " -----");
7474
getNamespacedPod(namespace).stream().forEach(System.out::println);
7575
} catch (ApiException ex) {
76-
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
76+
LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex);
7777
}
7878
});
7979

@@ -218,7 +218,7 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
218218
appsV1Api.replaceNamespacedDeployment(
219219
deploymentName, DEFAULT_NAME_SPACE, newDeploy).execute();
220220
} catch (ApiException ex) {
221-
LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
221+
LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex);
222222
}
223223
});
224224
}

extended/src/main/java/io/kubernetes/client/extended/controller/ControllerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* factory.
2525
*/
2626
public class ControllerManager implements Controller {
27-
private static final Logger log = LoggerFactory.getLogger(DefaultController.class);
27+
private static final Logger log = LoggerFactory.getLogger(ControllerManager.class);
2828
private Controller[] controllers;
2929
private ExecutorService controllerThreadPool;
3030
private SharedInformerFactory informerFactory;

spring-aot/src/main/java/io/kubernetes/client/spring/aot/KubernetesBeanFactoryInitializationAotProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public BeanFactoryInitializationAotContribution processAheadOfTime(
6464
"io.kubernetes.client.util.Watch$Response" //
6565
};
6666
for (String className : classNames) {
67-
LOGGER.info("registering " + className + " for reflection");
67+
LOGGER.info("registering {} for reflection", className);
6868
hints.reflection().registerType(TypeReference.of(className), allMemberCategories);
6969
}
7070
registerForPackage("io.kubernetes", hints);
@@ -85,7 +85,7 @@ private void registerForPackage(String packageName, RuntimeHints hints) {
8585
all.addAll(controllers);
8686
all.addAll(apiModels);
8787
for (Class<?> clazz : all) {
88-
LOGGER.info("registering " + clazz.getName() + " for reflection");
88+
LOGGER.info("registering {} for reflection", clazz.getName());
8989
hints.reflection().registerType(clazz, allMemberCategories);
9090
}
9191
}

spring/src/main/java/io/kubernetes/client/spring/extended/controller/config/KubernetesInformerAutoConfiguration.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public ApiClient defaultApiClient() throws IOException {
4141
ApiClient apiClient = ClientBuilder.defaultClient();
4242
return apiClient;
4343
} catch (Exception e) {
44-
LOGGER.warn(
45-
"Could not create a Kubernetes ApiClient from either a cluster or standard environment. "
46-
+ "Will return one that always connects to localhost:8080",
47-
e);
44+
LOGGER.warn("Could not create a Kubernetes ApiClient from either a cluster or standard environment. " + "Will return one that always connects to localhost:8080", e);
4845
return new ClientBuilder().build();
4946
}
5047
}

util/src/main/java/io/kubernetes/client/Copy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public Future<Integer> copyDirectoryFromPodAsync(
185185
entry != null;
186186
entry = archive.getNextEntry()) {
187187
if (!archive.canReadEntryData(entry)) {
188-
log.error("Can't read: " + entry);
188+
log.error("Can't read: {}", entry);
189189
continue;
190190
}
191191
String normalName = FilenameUtils.normalize(entry.getName());

util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private void watchHandler(Watchable<ApiType> watch) {
282282

283283
static <ApiType extends KubernetesObject> void defaultWatchErrorHandler(
284284
Class<ApiType> watchingApiTypeClass, Throwable t) {
285-
log.error(String.format("%s#Reflector loop failed unexpectedly", watchingApiTypeClass), t);
285+
log.error("{}#Reflector loop failed unexpectedly", watchingApiTypeClass, t);
286286
}
287287

288288
private boolean isConnectException(Throwable t) {

0 commit comments

Comments
 (0)