Bucket Logging Management
Updated at:2025-11-03
Application scenarios
- Create a BosClient.
- Execute the doesBucketExist() method.
If you expect to track requests accessing a certain bucket in BOS, you can enable the access logging function for that bucket
Set access logs
This API is designed to enable bucket access logs and specify the bucket for storing logs and the file prefix of access logs. For access log rules, refer to [Log Naming Rules](BOS/Developer Guide/Bucket Basic Operations/Set access logs.md#Log naming rules) and [Log Format](BOS/Developer Guide/Bucket Basic Operations/Set access logs.md#Log format).
-
Basic workflow
- Create a BosClient instance.
- Run the putBucketLogging() method.
- Example code
JavaScript
1 const logInfo = {
2 targetBucket: 'targetBucket',
3 targetPrefix: 'targetPrefix',
4 };
5 client.putBucketLogging(<BucketName>,<logInfo>)
6 .then(function(response) {
7 if(response) {
8 console.log('Bucket exists');
9 }
10 else {
11 console.log('Bucket not exists');
12 }
13 })
14 .catch(function() {});
- Request parameters
| Parameters | Types | Meaning | Required or not |
|---|---|---|---|
| BucketName | string | Bucket name | Yes |
| logInfo | Record<{targetBuckett: string, targetPrefix: string}> | Log configuration information | Yes |
| +targetBucket | string | Specified bucket for storing access logs | Yes |
| +targetPrefix | string | Specified bucket for storing access logs | No |
Get access log configuration
This API retrieves the access log configuration of a bucket.
-
Basic workflow
- Create a BosClient instance.
- Run the getBucketLogging() method.
- Example code
JavaScript
1 client.getBucketLogging(<BucketName>)
2 .then(function(response) {
3 if(response) {
4 console.log('Bucket exists');
5 }
6 else {
7 console.log('Bucket not exists');
8 }
9 })
10 .catch(function() {});
Delete access logs
-
Basic workflow
- Create a BosClient instance.
- Run the deleteBucketLogging() method.
- Example code
JavaScript
1 client.deleteBucketLogging(<BucketName>)
2 .then(function(response) {
3 if(response) {
4 console.log('Bucket exists');
5 }
6 else {
7 console.log('Bucket not exists');
8 }
9 })
10 .catch(function() {});
