Log Control
Application scenarios
If users need to track access requests to BOS, they can enable the BOS logging function and specify the bucket for storing logs and the file prefix of access logs. Each access log records detailed information about a single access request including information such as the requester, bucket name, request time, and request operation. The log can be applied in access statistics and security audits, etc.
Enable bucket log function
The following code enables the logging function of the bucket and specifies the prefix of the access log files to be finally saved:
1bos_client.put_bucket_logging(source_bucket, target_bucket, target_prefix)
Note:
- The user must own the source bucket with FULL_CONTROL permissions and also own the target bucket.
- The source and target buckets must reside in the same region.
- If the logging feature of the source bucket is enabled, its corresponding logging data will also be deleted when the source bucket is deleted.
- If the target bucket for logging is deleted, the logging feature of the source bucket will be automatically disabled.
- The "targetPrefix" represents the prefix for the object name used to store access logs, which can be left empty.
For detailed descriptions of parameters related to the logging function and configuration precautions, please refer to the [PutBucketLogging API](BOS/API Reference/Bucket-Related Interface/Logging/PutBucketLogging.md).
Query bucket logging function
The following code can query the configuration parameters of the bucket logging function:
1response = bos_client.get_bucket_logging(bucket_name)
The parameters available for calling in the resolution class returned by the get_bucket_logging method are as follows:
| Parameters | Description |
|---|---|
| status | Whether the logging function is enabled |
| targetBucket | The specified bucket for storing access logs. This field is absent in responses when the logging function is disabled. |
| targetPrefix | The specified prefix of access log files to be saved finally. This field is absent in responses when the logging function is disabled. |
Disable bucket log function
The following code can disable the bucket log function:
1bos_client.delete_bucket_logging(bucket_name)
