fix: log cannot be output and log information error (#101)

```release-note
修复无日志输出的问题
```
fixes #100 
测试上传,关联,删除,解除关联 4种操作的日志
```
---上传---
2023-11-27T22:39:22.139+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : operation: createMultipartUpload, result: CreateMultipartUploadResponse(Bucket=test-1305034426, Key=test/image-pjcl.png, UploadId=17010959629c897f8b8c1a592b0efe300de867a1ea3e891cf04b4f95c6986470a0f30195be)
2023-11-27T22:39:22.391+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : operation: uploadPart, result: UploadPartResponse(ETag="aa84eea735192b49552fa5bf3df317fa")
2023-11-27T22:39:22.547+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : operation: completeUpload, result: CompleteMultipartUploadResponse(Location=http://test-1305034426.cos.ap-guangzhou.myqcloud.com/test/image-pjcl.png, Bucket=test-1305034426, Key=test/image-pjcl.png, ETag="afdd5ce39cf49676238fcfc879664b55-1")
2023-11-27T22:39:22.616+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : operation: getMetadata, result: HeadObjectResponse(AcceptRanges=bytes, LastModified=2023-11-27T14:39:22Z, ContentLength=1420, ETag="afdd5ce39cf49676238fcfc879664b55-1", ContentType=image/png, Metadata={})
2023-11-27T22:39:22.616+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : Upload object test/image-pjcl.png to bucket test-1305034426 successfully
2023-11-27T22:39:22.626+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : Build attachment test/image-pjcl.png successfully
2023-11-27T22:39:29.915+08:00  WARN 7 --- [or-http-epoll-1] ocalVariableTableParameterNameDiscoverer : Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: run.halo.s3os.S3LinkController
---关联---
2023-11-27T22:39:34.657+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : Build attachment test/34.txt successfully
---解除关联---
2023-11-27T22:39:39.937+08:00  INFO 7 --- [tReconciler-t-1] run.halo.s3os.S3OsAttachmentHandler      : Skip deleting object test/34.txt from S3.
---删除---
2023-11-27T22:39:44.290+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : operation: delete object, result: DeleteObjectResponse()
2023-11-27T22:39:44.291+08:00  INFO 7 --- [oundedElastic-5] run.halo.s3os.S3OsAttachmentHandler      : Delete object test/image-pjcl.png from bucket test-1305034426 successfully
```
This commit is contained in:
longjuan
2023-12-01 15:40:09 +08:00
committed by GitHub
parent ac9c9b88a6
commit 3fda6e0cde
2 changed files with 14 additions and 4 deletions

View File

@@ -20,7 +20,10 @@ dependencies {
compileOnly 'run.halo.app:api'
implementation platform('software.amazon.awssdk:bom:2.19.8')
implementation 'software.amazon.awssdk:s3'
implementation ('software.amazon.awssdk:s3') {
exclude group: 'org.slf4j'
exclude group: 'commons-logging'
}
testImplementation 'run.halo.app:api'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

View File

@@ -91,8 +91,14 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return Mono.just(deleteContext).filter(context -> this.shouldHandle(context.policy()))
.flatMap(context -> {
var objectKey = getObjectKey(context.attachment());
if (objectKey == null || MetadataUtil.nullSafeAnnotations(context.attachment())
if (objectKey == null) {
log.warn(
"Cannot obtain object key from attachment {}, skip deleting object from S3.",
context.attachment().getMetadata().getName());
return Mono.just(context);
} else if (MetadataUtil.nullSafeAnnotations(context.attachment())
.containsKey(SKIP_REMOTE_DELETION_ANNO)) {
log.info("Skip deleting object {} from S3.", objectKey);
return Mono.just(context);
}
var properties = getProperties(deleteContext.configMap());
@@ -216,8 +222,7 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
var attachment = new Attachment();
attachment.setMetadata(metadata);
attachment.setSpec(spec);
log.info("Upload object {} to bucket {} successfully", objectDetail.uploadState.objectKey,
properties.getBucket());
log.info("Built attachment {} successfully", objectDetail.uploadState.objectKey);
return attachment;
}
@@ -368,6 +373,8 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
// build object detail
.map((response) -> {
checkResult(response, "getMetadata");
log.info("Uploaded object {} to bucket {} successfully",
uploadState.objectKey, properties.getBucket());
return new ObjectDetail(uploadState, response);
})
// close client