From b4374aa131d03db4cf2b5c88f83815686116ebc4 Mon Sep 17 00:00:00 2001 From: KaimingWan Date: Fri, 12 Jan 2024 16:32:37 +0800 Subject: [PATCH] chore(tool): do not use system err because automq admin tool suppress this to avoid slf4j's inner warning logs --- .../java/com/automq/stream/utils/S3Utils.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/s3stream/src/main/java/com/automq/stream/utils/S3Utils.java b/s3stream/src/main/java/com/automq/stream/utils/S3Utils.java index 5c56dcfa2..4a794ef2e 100644 --- a/s3stream/src/main/java/com/automq/stream/utils/S3Utils.java +++ b/s3stream/src/main/java/com/automq/stream/utils/S3Utils.java @@ -119,11 +119,12 @@ public S3CheckTask(S3Context context, String taskName) { protected static void showErrorInfo(Exception e) { if (e.getCause() instanceof S3Exception se) { - System.err.println("get S3 exception: "); - se.printStackTrace(); + // Do not use system.err because automq admin tool suppress system.err + System.out.println("get S3 exception: "); + se.printStackTrace(System.out); } else { - System.err.println("get other exception: "); - e.printStackTrace(); + System.out.println("get other exception: "); + e.printStackTrace(System.out); } } @@ -201,7 +202,7 @@ private CompletableFuture createMultipartUpload(S3AsyncClient writeS3Cli writeS3Client.createMultipartUpload(request).thenAccept(createMultipartUploadResponse -> { cf.complete(createMultipartUploadResponse.uploadId()); }).exceptionally(ex -> { - System.err.println("[ FAILED ] Upload s3 multipart object"); + System.out.println("[ FAILED ] Upload s3 multipart object"); cf.completeExceptionally(ex); return null; }); @@ -217,7 +218,7 @@ public CompletableFuture completeMultipartUpload(S3AsyncClient writeS3Clie writeS3Client.completeMultipartUpload(request).thenAccept(completeMultipartUploadResponse -> { cf.complete(null); }).exceptionally(ex -> { - System.err.println("[ FAILED ] Upload s3 multipart object, upload id is "+uploadId); + System.out.println("[ FAILED ] Upload s3 multipart object, upload id is "+uploadId); cf.completeExceptionally(ex); return null; }); @@ -275,16 +276,16 @@ public void run() { readRange(client, path, readCf, bucketName, 0, -1); byteBuf = readCf.get(); if (byteBuf == null) { - System.err.println("[ Failed ] Read s3 object"); + System.out.println("[ Failed ] Read s3 object"); throw new RuntimeException("read object " + path + " fail. got null"); } else if (byteBuf.readableBytes() != content.length) { - System.err.println("[ Failed ] Read s3 object"); + System.out.println("[ Failed ] Read s3 object"); throw new RuntimeException("read object " + path + " fail. expected size " + content.length + ", actual size " + byteBuf.readableBytes()); } byte[] readContent = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(readContent); if (!StringUtils.equals(new String(readContent, StandardCharsets.UTF_8), new String(content, StandardCharsets.UTF_8))) { - System.err.println("[ Failed ] Read s3 object"); + System.out.println("[ Failed ] Read s3 object"); throw new RuntimeException("read object " + path + " fail. expected content " + new String(content, StandardCharsets.UTF_8) + ", actual content " + new String(readContent, StandardCharsets.UTF_8)); } System.out.println("[ OK ] Read s3 object"); @@ -305,7 +306,7 @@ private void writeObject(S3AsyncClient writeS3Client, String path, ByteBuffer da writeS3Client.putObject(request, body).thenAccept(putObjectResponse -> { cf.complete(null); }).exceptionally(ex -> { - System.err.printf("[ Failed ] Write s3 object. PutObject for object %s fail with msg %s %n", path, ex.getMessage()); + System.out.printf("[ Failed ] Write s3 object. PutObject for object %s fail with msg %s %n", path, ex.getMessage()); cf.completeExceptionally(ex); return null; }); @@ -335,7 +336,7 @@ protected void deleteObject(S3AsyncClient deleteS3Client, String path, Completab deleteS3Client.deleteObject(request).thenAccept(deleteObjectResponse -> { cf.complete(null); }).exceptionally(ex -> { - System.err.printf("[ FAILED ] Delete s3 object. Delete object %s fail with msg %s %n", path, ex.getMessage()); + System.out.printf("[ FAILED ] Delete s3 object. Delete object %s fail with msg %s %n", path, ex.getMessage()); cf.completeExceptionally(ex); return null; }); @@ -349,7 +350,7 @@ public void close() { deleteCf.get(); } catch (InterruptedException | ExecutionException e) { - System.err.println("[ FAILED ] Delete s3 object. NOTICE: please delete object " + path + " manually!!!"); + System.out.println("[ FAILED ] Delete s3 object. NOTICE: please delete object " + path + " manually!!!"); showErrorInfo(e); throw new RuntimeException(e); } finally {