Skip to content

Commit

Permalink
chore: use parameterized messages instead of string formatting for lo…
Browse files Browse the repository at this point in the history
…gging (#699)
  • Loading branch information
sam0r040 authored Apr 19, 2024
1 parent 49f7943 commit 5f9a5bd
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ private void processAsyncApiPayloadAnnotation(Map<String, Schema> 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public ResponseEntity<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void send(String channelName, Map<String, String> 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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void send(String topic, String key, Map<String, String> 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);
}
}

Expand Down

0 comments on commit 5f9a5bd

Please sign in to comment.