From 197a52584a1755abb310c74442f2b1761f8cec75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=B0=8F=E5=B9=B3?= Date: Mon, 28 Oct 2024 15:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3sonar=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E5=BC=82=E5=91=B3=E3=80=82Define=20a=20constant=20instead=20of?= =?UTF-8?q?=20duplicating=20this=20literal=20"{}:{}"=209=20times.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s3/official/MinioS3ClientImpl.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/minio-plus-s3-api/s3-api-minio/src/main/java/org/liuxp/minioplus/s3/official/MinioS3ClientImpl.java b/minio-plus-s3-api/s3-api-minio/src/main/java/org/liuxp/minioplus/s3/official/MinioS3ClientImpl.java index 9c30b6e..6ee38ca 100644 --- a/minio-plus-s3-api/s3-api-minio/src/main/java/org/liuxp/minioplus/s3/official/MinioS3ClientImpl.java +++ b/minio-plus-s3-api/s3-api-minio/src/main/java/org/liuxp/minioplus/s3/official/MinioS3ClientImpl.java @@ -37,6 +37,10 @@ public class MinioS3ClientImpl implements MinioS3Client { * 分片上传块号名称 */ private static final String PART_NUMBER = "partNumber"; + /** + * 日志打印 + */ + private static final String LOG_TEMPLATE = "{}:{}"; private final MinioPlusProperties properties; @@ -65,11 +69,11 @@ public class MinioS3ClientImpl implements MinioS3Client { return this.getClient().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()).get(); } catch (InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | XmlParserException | ExecutionException e) { - log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED); } catch (InterruptedException e){ Thread.currentThread().interrupt(); // 重新设置中断状态 - log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED); } } @@ -83,7 +87,7 @@ public class MinioS3ClientImpl implements MinioS3Client { this.getClient().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); } } catch (Exception e) { - log.error("{}:{}", MinioPlusErrorCode.MAKE_BUCKET_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.MAKE_BUCKET_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.MAKE_BUCKET_FAILED); } } @@ -94,7 +98,7 @@ public class MinioS3ClientImpl implements MinioS3Client { CreateMultipartUploadResponse createMultipartUploadResponse = this.getClient().createMultipartUpload(bucketName, null, objectName, null, null); return createMultipartUploadResponse.result().uploadId(); } catch (Exception e) { - log.error("{}:{}", MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED); } } @@ -139,7 +143,7 @@ public class MinioS3ClientImpl implements MinioS3Client { } catch (Exception e) { // 查询分片失败,打印日志,返回空的分片信息 - log.error("{}:{}", MinioPlusErrorCode.LIST_PARTS_FAILED.getMessage(), e.getMessage()); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.LIST_PARTS_FAILED.getMessage(), e.getMessage()); } return listParts; @@ -162,7 +166,7 @@ public class MinioS3ClientImpl implements MinioS3Client { .extraQueryParams(queryParams) .build()); } catch (Exception e) { - log.error("{}:{}", MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED); } } @@ -183,7 +187,7 @@ public class MinioS3ClientImpl implements MinioS3Client { .extraQueryParams(reqParams) .build()); } catch (Exception e) { - log.error("{}:{}", MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED); } } @@ -204,7 +208,7 @@ public class MinioS3ClientImpl implements MinioS3Client { .extraQueryParams(reqParams) .build()); } catch (Exception e) { - log.error("{}:{}", MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED); } } @@ -235,7 +239,7 @@ public class MinioS3ClientImpl implements MinioS3Client { throw new MinioPlusException(MinioPlusErrorCode.WRITE_FAILED); } catch (InterruptedException e){ Thread.currentThread().interrupt(); // 重新设置中断状态 - log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); + log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e); throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED); }