Skip to content

Commit 40f92a7

Browse files
committed
fix: replace printStackTrace() calls with proper logging
Replace all printStackTrace() calls with proper SLF4J logging throughout the codebase: - Production code: Use log.error(), log.warn(), or log.debug() as appropriate - Test code: Use logger from base class or add SLF4J logger - Examples: Use System.err.println() for standalone demo apps - Build tools: Add SLF4J logging Also added slf4j-api dependency to schema-resolver module. Fixes #7070
1 parent b39df2e commit 40f92a7

File tree

13 files changed

+59
-23
lines changed

13 files changed

+59
-23
lines changed

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/AllYamlTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
import io.quarkus.test.junit.QuarkusTest;
1919
import org.junit.jupiter.api.Assertions;
2020
import org.junit.jupiter.api.Test;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2123

2224
import java.util.UUID;
2325

2426
@QuarkusTest
2527
public class AllYamlTest extends AbstractResourceTestBase {
2628

29+
private static final Logger log = LoggerFactory.getLogger(AllYamlTest.class);
30+
2731
private static String YAML_CONTENT = """
2832
openapi: 3.0.2
2933
info:
@@ -125,8 +129,7 @@ public void testCreateYamlArtifactWithValidity() throws Exception {
125129
YAML_CONTENT, ContentTypes.APPLICATION_YAML);
126130
clientV3.groups().byGroupId(groupId).artifacts().post(createArtifact);
127131
} catch (ProblemDetails e) {
128-
System.out.println("ERROR: " + e.getDetail());
129-
e.getCause().printStackTrace();
132+
log.error("Failed to create YAML artifact: {}", e.getDetail(), e.getCause());
130133
throw e;
131134
}
132135
}

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/ImportExportTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import jakarta.inject.Inject;
3131
import org.junit.jupiter.api.Assertions;
3232
import org.junit.jupiter.api.Test;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
3335

3436
import java.io.File;
3537
import java.io.FileInputStream;
@@ -47,6 +49,8 @@
4749
@QuarkusTest
4850
public class ImportExportTest extends AbstractResourceTestBase {
4951

52+
private static final Logger log = LoggerFactory.getLogger(ImportExportTest.class);
53+
5054
@Inject
5155
@Current
5256
RegistryStorage storage;
@@ -334,17 +338,17 @@ private static void downloadTo(URL url, File tempFile) {
334338
}
335339

336340
private static void listFiles(File tempFile) {
337-
System.out.println("--- Export ZIP File Listing ---");
341+
log.debug("--- Export ZIP File Listing ---");
338342
try (ZipFile zipFile = new ZipFile(tempFile)) {
339343
Enumeration<? extends ZipEntry> entries = zipFile.entries();
340344
while (entries.hasMoreElements()) {
341345
ZipEntry entry = entries.nextElement();
342-
System.out.println(entry.getName());
346+
log.debug(entry.getName());
343347
}
344348
} catch (IOException e) {
345-
e.printStackTrace();
349+
log.warn("Failed to list ZIP file entries", e);
346350
}
347-
System.out.println("--- Export ZIP File Listing ---");
351+
log.debug("--- Export ZIP File Listing ---");
348352
}
349353

350354
}

docs/config-generator/src/main/java/io/apicurio/registry/docs/GenerateAllConfigPartial.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.jboss.jandex.IndexReader;
88
import org.jboss.jandex.Main;
99
import org.jboss.jandex.Type;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
import java.io.FileInputStream;
1214
import java.io.FileNotFoundException;
@@ -51,6 +53,8 @@
5153
*/
5254
public class GenerateAllConfigPartial {
5355

56+
private static final Logger log = LoggerFactory.getLogger(GenerateAllConfigPartial.class);
57+
5458
private static Map<String, Option> allConfiguration = new HashMap();
5559
private static Set<String> skipProperties = Set.of("quarkus.oidc.auth-server-url");
5660

@@ -161,19 +165,21 @@ public static Map<String, Option> extractConfigurations(String jarFile, Map<Stri
161165
try {
162166
input = new FileInputStream(jarFile.replace(".jar", "-jar.idx"));
163167
} catch (FileNotFoundException e) {
164-
e.printStackTrace();
168+
log.error("Jandex index file not found for JAR: {}", jarFile, e);
169+
throw new RuntimeException("Jandex index file not found", e);
165170
}
166171
IndexReader reader = new IndexReader(input);
167172
Index index = null;
168173
try {
169174
index = reader.read();
170175
} catch (IOException e) {
171-
e.printStackTrace();
176+
log.error("Failed to read Jandex index for JAR: {}", jarFile, e);
177+
throw new RuntimeException("Failed to read Jandex index", e);
172178
} finally {
173179
try {
174180
input.close();
175181
} catch (IOException e) {
176-
e.printStackTrace();
182+
log.warn("Failed to close Jandex index input stream", e);
177183
}
178184
}
179185

@@ -322,7 +328,7 @@ public static void main(String... args) throws Exception {
322328
//load a properties file from class path, inside static method
323329
props.load(new FileInputStream(baseDir + "/../app/src/main/resources/application.properties"));
324330
} catch (Exception e) {
325-
e.printStackTrace();
331+
log.warn("Failed to load application.properties for configuration extraction", e);
326332
}
327333
for (var prop : props.entrySet()) {
328334

examples/mtls-minikube/client/src/main/java/io/apicurio/registry/examples/mtls/MtlsClientDemo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ public static void main(String[] args) {
161161
}
162162

163163
System.err.println();
164-
System.err.println("Error details:");
165-
e.printStackTrace();
164+
System.err.println("Error details: " + e.getMessage());
165+
if (e.getCause() != null) {
166+
System.err.println("Caused by: " + e.getCause().getMessage());
167+
}
166168
System.exit(1);
167169
} finally {
168170
// Clean up Vert.x instance

examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/MessagePublisher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void publishMessage(MessageBean message) {
5959
}
6060
} catch (Exception e) {
6161
System.err.println("Error publishing message: " + e.getMessage());
62-
e.printStackTrace();
6362
}
6463
}
6564

examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/SimpleBroker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void start() {
5757

5858
server.start();
5959
} catch (Throwable tr) {
60-
tr.printStackTrace();
60+
System.err.println("Failed to start SimpleBroker: " + tr.getMessage());
6161
}
6262
}
6363

integration-tests/src/test/java/io/apicurio/tests/auth/SimpleAuthIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void testDevRole() throws Exception {
157157
try {
158158
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete();
159159
} catch (Exception ex) {
160-
ex.printStackTrace();
160+
logger.warn("Failed to delete test artifact during cleanup", ex);
161161
}
162162
}
163163
}
@@ -199,7 +199,7 @@ public void testAdminRole() throws Exception {
199199
try {
200200
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete();
201201
} catch (Exception ex) {
202-
ex.printStackTrace();
202+
logger.warn("Failed to delete test artifact during cleanup", ex);
203203
}
204204
}
205205
}

integration-tests/src/test/java/io/apicurio/tests/migration/GenerateCanonicalHashImportIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.junit.jupiter.api.Disabled;
2323
import org.junit.jupiter.api.Tag;
2424
import org.junit.jupiter.api.Test;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2527

2628
import java.io.ByteArrayInputStream;
2729
import java.io.ByteArrayOutputStream;
@@ -44,6 +46,8 @@
4446
@Disabled
4547
public class GenerateCanonicalHashImportIT extends ApicurioRegistryBaseIT {
4648

49+
private static final Logger log = LoggerFactory.getLogger(GenerateCanonicalHashImportIT.class);
50+
4751
@Test
4852
public void testGeneratingCanonicalHashOnImport() throws Exception {
4953
Vertx vertx = Vertx.vertx();
@@ -171,7 +175,7 @@ public InputStream generateExportedZip(Map<String, String> artifacts) {
171175

172176
return new ByteArrayInputStream(outputStream.toByteArray());
173177
} catch (IOException e) {
174-
e.printStackTrace();
178+
log.error("Failed to generate exported ZIP", e);
175179
}
176180
return null;
177181
}

integration-tests/src/test/java/io/apicurio/tests/migration/MigrationTestsDataInitializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
import java.util.concurrent.atomic.AtomicInteger;
3434
import java.util.zip.ZipOutputStream;
3535

36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
38+
3639
import static io.apicurio.tests.migration.DataMigrationIT.doNotPreserveIdsImportArtifacts;
3740
import static io.apicurio.tests.migration.DataMigrationIT.migrateGlobalIds;
3841
import static io.apicurio.tests.migration.DataMigrationIT.migrateReferencesMap;
3942
import static org.junit.jupiter.api.Assertions.assertTrue;
4043

4144
public class MigrationTestsDataInitializer {
4245

46+
private static final Logger log = LoggerFactory.getLogger(MigrationTestsDataInitializer.class);
47+
4348
public static void initializeMigrateTest(io.apicurio.registry.rest.client.v2.RegistryClient source,
4449
String registryBaseUrl) throws Exception {
4550
migrateGlobalIds = new ArrayList<>();
@@ -293,7 +298,7 @@ public InputStream generateExportedZip(Map<String, String> artifacts) {
293298

294299
return new ByteArrayInputStream(outputStream.toByteArray());
295300
} catch (IOException e) {
296-
e.printStackTrace();
301+
log.error("Failed to generate exported ZIP", e);
297302
}
298303
return null;
299304
}

schema-resolver/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<artifactId>apicurio-registry-common</artifactId>
3232
</dependency>
3333

34+
<dependency>
35+
<groupId>org.slf4j</groupId>
36+
<artifactId>slf4j-api</artifactId>
37+
</dependency>
38+
3439
<dependency>
3540
<groupId>org.projectlombok</groupId>
3641
<artifactId>lombok</artifactId>

0 commit comments

Comments
 (0)