From 4c77a56f3ec7dc9b390f41ec2789dc69f8bc422f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller?= Date: Fri, 12 Apr 2024 12:11:49 +0200 Subject: [PATCH] chore: use parameterized messages instead of string formatting for logging --- .../addons/json_schema/JsonSchemaCustomizer.java | 4 ++-- .../springwolf/core/asyncapi/DefaultAsyncApiService.java | 3 +-- .../core/asyncapi/components/DefaultComponentsService.java | 7 ++++--- .../components/examples/walkers/DefaultSchemaWalker.java | 2 +- .../scanners/common/payload/PayloadClassExtractor.java | 4 ++-- .../core/controller/PublishingBaseController.java | 3 +-- .../io/github/springwolf/examples/amqp/ApiSystemTest.java | 2 +- .../springwolf/examples/cloudstream/ApiSystemTest.java | 2 +- .../io/github/springwolf/examples/kafka/ApiSystemTest.java | 2 +- .../io/github/springwolf/examples/sns/ApiSystemTest.java | 2 +- .../io/github/springwolf/examples/sqs/ApiSystemTest.java | 2 +- .../plugins/jms/producer/SpringwolfJmsProducer.java | 2 +- .../plugins/kafka/producer/SpringwolfKafkaProducer.java | 2 +- 13 files changed, 18 insertions(+), 19 deletions(-) diff --git a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizer.java b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizer.java index 564537386..1413d9d28 100644 --- a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizer.java +++ b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizer.java @@ -29,12 +29,12 @@ public void customize(AsyncAPI asyncAPI) { } try { - log.debug("Generate json-schema for %s".formatted(entry.getKey())); + log.debug("Generate json-schema for {}", entry.getKey()); Object jsonSchema = jsonSchemaGenerator.fromSchema(schema, schemas); schema.getExtensionFields().putIfAbsent(EXTENSION_JSON_SCHEMA, jsonSchema); } catch (Exception ex) { - log.warn("Unable to create json-schema for %s".formatted(entry.getKey()), ex); + log.warn("Unable to create json-schema for {}", entry.getKey(), ex); } } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/DefaultAsyncApiService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/DefaultAsyncApiService.java index 12af68eab..713f22117 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/DefaultAsyncApiService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/DefaultAsyncApiService.java @@ -86,8 +86,7 @@ protected synchronized void initAsyncAPI() { .build(); for (AsyncApiCustomizer customizer : customizers) { - log.debug( - "Starting customizer %s".formatted(customizer.getClass().getName())); + log.debug("Starting customizer {}", customizer.getClass().getName()); customizer.customize(asyncAPI); } this.asyncAPIResult = new AsyncAPIResult(asyncAPI, null); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java index 1df1bb520..307d58705 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java @@ -150,9 +150,10 @@ private void processAsyncApiPayloadAnnotation(Map schemas, Strin } } else if (withPayloadAnnotatedFields.size() > 1) { - log.warn(("Found more than one field with @AsyncApiPayload annotation in class %s. " - + "Falling back and ignoring annotation.") - .formatted(type.getName())); + log.warn( + ("Found more than one field with @AsyncApiPayload annotation in class {}. " + + "Falling back and ignoring annotation."), + type.getName()); } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java index 2ba66f07a..aeb81aa48 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java @@ -110,7 +110,7 @@ private T getExampleValueFromSchemaAnnotation(Schema schema) { // value (i.e. OffsetDateTime) is represented as string return exampleValueGenerator.createStringExample(exampleValue.toString()); } catch (IllegalArgumentException ex) { - log.debug("Unable to convert example to JSON: %s".formatted(exampleValue.toString()), ex); + log.debug("Unable to convert example to JSON: {}", exampleValue, ex); } return exampleValueGenerator.createEmptyObjectExample(); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/payload/PayloadClassExtractor.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/payload/PayloadClassExtractor.java index 7f2bf9644..0d19c5e69 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/payload/PayloadClassExtractor.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/payload/PayloadClassExtractor.java @@ -99,7 +99,7 @@ private Class extractClass(Type parameterType) { // no generics used - just a normal type return Class.forName(parameterType.getTypeName()); } catch (Exception ex) { - log.info("Unable to extract generic data type of %s".formatted(parameterType), ex); + log.info("Unable to extract generic data type of {}", parameterType, ex); } return Void.class; } @@ -122,7 +122,7 @@ private Class extractActualGenericClass(ParameterizedType parameterType, Stri try { return Class.forName(typeName); } catch (ClassNotFoundException ex) { - log.debug("Unable to find class for type %s".formatted(typeName), ex); + log.debug("Unable to find class for type {}", typeName, ex); } return Void.class; diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/controller/PublishingBaseController.java b/springwolf-core/src/main/java/io/github/springwolf/core/controller/PublishingBaseController.java index 6cddacbbe..6647d517e 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/controller/PublishingBaseController.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/controller/PublishingBaseController.java @@ -44,7 +44,6 @@ public ResponseEntity publish(@RequestParam String topic, @RequestBody M @Override public void afterPropertiesSet() { - log.debug( - "Message publishing via %s is active.".formatted(this.getClass().getSimpleName())); + log.debug("Message publishing via {} is active.", this.getClass().getSimpleName()); } } diff --git a/springwolf-examples/springwolf-amqp-example/src/test/java/io/github/springwolf/examples/amqp/ApiSystemTest.java b/springwolf-examples/springwolf-amqp-example/src/test/java/io/github/springwolf/examples/amqp/ApiSystemTest.java index 8ba00c4ac..acf71965a 100644 --- a/springwolf-examples/springwolf-amqp-example/src/test/java/io/github/springwolf/examples/amqp/ApiSystemTest.java +++ b/springwolf-examples/springwolf-amqp-example/src/test/java/io/github/springwolf/examples/amqp/ApiSystemTest.java @@ -48,7 +48,7 @@ public class ApiSystemTest { public static DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) .withExposedService(APP_NAME, APP_PORT) .withEnv(ENV) - .withLogConsumer(APP_NAME, l -> log.debug("APP: %s".formatted(l.getUtf8StringWithoutLineEnding()))); + .withLogConsumer(APP_NAME, l -> log.debug("APP: {}", l.getUtf8StringWithoutLineEnding())); private String baseUrl() { String host = environment.getServiceHost(APP_NAME, APP_PORT); diff --git a/springwolf-examples/springwolf-cloud-stream-example/src/test/java/io/github/springwolf/examples/cloudstream/ApiSystemTest.java b/springwolf-examples/springwolf-cloud-stream-example/src/test/java/io/github/springwolf/examples/cloudstream/ApiSystemTest.java index e3f9c1517..6845d6753 100644 --- a/springwolf-examples/springwolf-cloud-stream-example/src/test/java/io/github/springwolf/examples/cloudstream/ApiSystemTest.java +++ b/springwolf-examples/springwolf-cloud-stream-example/src/test/java/io/github/springwolf/examples/cloudstream/ApiSystemTest.java @@ -48,7 +48,7 @@ public class ApiSystemTest { public static DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) .withExposedService(APP_NAME, APP_PORT) .withEnv(ENV) - .withLogConsumer(APP_NAME, l -> log.debug("APP: %s".formatted(l.getUtf8StringWithoutLineEnding()))); + .withLogConsumer(APP_NAME, l -> log.debug("APP: {}", l.getUtf8StringWithoutLineEnding())); private String baseUrl() { String host = environment.getServiceHost(APP_NAME, APP_PORT); diff --git a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiSystemTest.java b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiSystemTest.java index 51486bc91..48319c403 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiSystemTest.java +++ b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiSystemTest.java @@ -48,7 +48,7 @@ public class ApiSystemTest { public static DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) .withExposedService(APP_NAME, APP_PORT) .withEnv(ENV) - .withLogConsumer(APP_NAME, l -> log.debug("APP: %s".formatted(l.getUtf8StringWithoutLineEnding()))); + .withLogConsumer(APP_NAME, l -> log.debug("APP: {}", l.getUtf8StringWithoutLineEnding())); private String baseUrl() { String host = environment.getServiceHost(APP_NAME, APP_PORT); diff --git a/springwolf-examples/springwolf-sns-example/src/test/java/io/github/springwolf/examples/sns/ApiSystemTest.java b/springwolf-examples/springwolf-sns-example/src/test/java/io/github/springwolf/examples/sns/ApiSystemTest.java index 81c3c5d19..94ba93faa 100644 --- a/springwolf-examples/springwolf-sns-example/src/test/java/io/github/springwolf/examples/sns/ApiSystemTest.java +++ b/springwolf-examples/springwolf-sns-example/src/test/java/io/github/springwolf/examples/sns/ApiSystemTest.java @@ -48,7 +48,7 @@ public class ApiSystemTest { public DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) .withExposedService(APP_NAME, APP_PORT) .withEnv(ENV) - .withLogConsumer(APP_NAME, l -> log.debug("APP: %s".formatted(l.getUtf8StringWithoutLineEnding()))); + .withLogConsumer(APP_NAME, l -> log.debug("APP: {}", l.getUtf8StringWithoutLineEnding())); private String baseUrl() { String host = environment.getServiceHost(APP_NAME, APP_PORT); diff --git a/springwolf-examples/springwolf-sqs-example/src/test/java/io/github/springwolf/examples/sqs/ApiSystemTest.java b/springwolf-examples/springwolf-sqs-example/src/test/java/io/github/springwolf/examples/sqs/ApiSystemTest.java index ef9576f4f..4435bab85 100644 --- a/springwolf-examples/springwolf-sqs-example/src/test/java/io/github/springwolf/examples/sqs/ApiSystemTest.java +++ b/springwolf-examples/springwolf-sqs-example/src/test/java/io/github/springwolf/examples/sqs/ApiSystemTest.java @@ -48,7 +48,7 @@ public class ApiSystemTest { public DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) .withExposedService(APP_NAME, APP_PORT) .withEnv(ENV) - .withLogConsumer(APP_NAME, l -> log.debug("APP: %s".formatted(l.getUtf8StringWithoutLineEnding()))); + .withLogConsumer(APP_NAME, l -> log.debug("APP: {}", l.getUtf8StringWithoutLineEnding())); private String baseUrl() { String host = environment.getServiceHost(APP_NAME, APP_PORT); diff --git a/springwolf-plugins/springwolf-jms-plugin/src/main/java/io/github/springwolf/plugins/jms/producer/SpringwolfJmsProducer.java b/springwolf-plugins/springwolf-jms-plugin/src/main/java/io/github/springwolf/plugins/jms/producer/SpringwolfJmsProducer.java index 848484744..62aa723c9 100644 --- a/springwolf-plugins/springwolf-jms-plugin/src/main/java/io/github/springwolf/plugins/jms/producer/SpringwolfJmsProducer.java +++ b/springwolf-plugins/springwolf-jms-plugin/src/main/java/io/github/springwolf/plugins/jms/producer/SpringwolfJmsProducer.java @@ -30,7 +30,7 @@ public void send(String channelName, Map headers, Object payload try { message.setStringProperty(name, value); } catch (JMSException ex) { - log.warn("Unable to set JMS Header key=%s value=%s".formatted(name, value), ex); + log.warn("Unable to set JMS Header key={} value={}", name, value, ex); } }); } diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/producer/SpringwolfKafkaProducer.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/producer/SpringwolfKafkaProducer.java index 682c9b367..552470f5a 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/producer/SpringwolfKafkaProducer.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/producer/SpringwolfKafkaProducer.java @@ -35,7 +35,7 @@ public void send(String topic, String key, Map headers, Object p .toCompletableFuture() .join(); } else { - log.warn("Kafka producer for topic %s is not configured".formatted(topic)); + log.warn("Kafka producer for topic {} is not configured", topic); } }