日志管理
更新时间:2026-08-11
PutBucketLogging
本接口用来开启Bucket的访问日志并指定存放日志的Bucket和访问日志的文件前缀。访问日志的规则请参见日志命名规则和日志格式。
注意事项
- 用户必须是源Bucket的owner且拥有FULL_CONTROL权限,且是目标Bucket的owner。
- 源Bucket和目标Bucket必须同时存在。
- 源Bucket和目标Bucket必须属于同一个Region。
- 如果HTTP Body中Json不合法,BOS会返回CODE_MALFORMED_JSON错误。
- 如果HTTP Body中Json有无效字段,BOS会返回CODE_INAPPROPRIATE_JSON错误。
- 用户可将不同的源Bucket的Logging都保存在同一个目标Bucket内,建议指定不同的 targetPrefix便于区分。
- 如果源Bucket开通了Logging功能,源Bucket被删除的同时,相应的Logging信息也将被删除。
- 如果Logging的目标Bucket被删除,则源Bucket的Logging功能会被自动关闭。
- 如果需要修改目标Bucket等信息,可再发送一个PutBucketLogging请求,请求中包含需要修改的信息。
- targetPrefix表示存储访问日志记录的Object名字前缀,可以为空。如果不为空时,targetPrefix可以包含字母、数字、中划线、下划线、斜杠,且必须以字母开头,长度不大于32位。
- 重复请求返回结果相同。
相关参数参见PutBucketLogging接口。
C++
1void put_bucket_logging(Client &client) {
2 PutBucketLoggingRequest request(g_bucket, g_bucket);
3 request.set_target_prefix("logs/");
4 PutBucketLoggingResponse response;
5 client.put_bucket_logging(request, &response);
6 print_common_response(response);
7}
GetBucketLogging
本接口用来获取某个Bucket的访问日志配置情况。
注意事项
- 如果请求的源Bucket不存在,返回404错误,错误码为NoSuchBucket。
- 请求者只有是源Bucket的owner且拥有FULL_CONTROL权限才允许查看,否则返回403错误,错误码为AccessDenied。
相关参数参见GetBucketLogging接口。
C++
1void get_bucket_logging(Client &client) {
2 GetBucketLoggingRequest request(g_bucket);
3 GetBucketLoggingResponse response;
4 client.get_bucket_logging(request, &response);
5 print_common_response(response);
6 if (response.is_fail()) {
7 return;
8 }
9
10 std::cout << "status: " << response.Status() << std::endl;
11 std::cout << "targetBucket: " << response.Bucket() << std::endl;
12 std::cout << "targetPrefix: " << response.Prefix() << std::endl;
13}
DeleteBucketLogging
本接口用来关闭Bucket访问日志记录功能。
注意事项
- 如果请求的源Bucket不存在,返回404错误,错误码为NoSuchBucket。
- 请求者只有是源Bucket的owner且拥有FULL_CONTROL权限,才能关闭Bucket访问日志记录功能。否则,BOS返回403错误,错误码为AccessDenied。
- 如果请求的源Bucket没有开通Logging功能,依然返回HTTP状态码204。
相关参数参见DeleteBucketLogging接口。
C++
1void delete_bucket_logging(Client &client) {
2 DeleteBucketLoggingRequest request(g_bucket);
3 DeleteBucketLoggingResponse response;
4 client.delete_bucket_logging(request, &response);
5 print_common_response(response);
6}
评价此篇文章
