日志管理
更新时间:2026-09-20
put_bucket_logging
本接口用来开启Bucket的访问日志并指定存放日志的Bucket和访问日志的文件前缀。访问日志的规则请参见日志命名规则和日志格式。
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bos.bos_client import BosClient
4
5access_key_id = 'your-access-key-id'
6secret_access_key = 'your-secret-access-key'
7endpoint = 'https://bj.bcebos.com'
8source_bucket = 'source-bucket-name'
9target_bucket = 'target-bucket-name'
10prefix = "myPrefix/"
11
12config = BceClientConfiguration(
13 credentials=BceCredentials(access_key_id, secret_access_key),
14 endpoint=endpoint
15)
16bos_client = BosClient(config)
17
18bos_client.put_bucket_logging(source_bucket, target_bucket, prefix)
get_bucket_logging
本接口用来获取某个Bucket的访问日志配置情况。
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bos.bos_client import BosClient
4
5access_key_id = 'your-access-key-id'
6secret_access_key = 'your-secret-access-key'
7endpoint = 'https://bj.bcebos.com'
8bucket_name = 'example-bucket-name'
9
10config = BceClientConfiguration(
11 credentials=BceCredentials(access_key_id, secret_access_key),
12 endpoint=endpoint
13)
14bos_client = BosClient(config)
15
16response = bos_client.get_bucket_logging(bucket_name)
delete_bucket_logging
本接口用来删除某个Bucket的访问日志配置。
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bos.bos_client import BosClient
4
5access_key_id = 'your-access-key-id'
6secret_access_key = 'your-secret-access-key'
7endpoint = 'https://bj.bcebos.com'
8bucket_name = 'example-bucket-name'
9
10config = BceClientConfiguration(
11 credentials=BceCredentials(access_key_id, secret_access_key),
12 endpoint=endpoint
13)
14bos_client = BosClient(config)
15
16bos_client.delete_bucket_logging(bucket_name)
评价此篇文章
