Enable bucket access logs
Updated at:2025-11-03
API description
This API is used to enable access logging for a bucket, specify the bucket where the logs will be stored, and set the file prefix for the access logs. For access log rules, refer to Log Naming Rules and Log Format.
Notes
- The user must own the source bucket with FULL_CONTROL permissions and also own the target bucket.
- Both the source and target buckets must exist.
- The source and target buckets must reside in the same region.
- Invalid JSON in the HTTP Body triggers a CODE_MALFORMED_JSON error from BOS.
- If the JSON in the HTTP Body contains invalid fields, BOS will return a CODE_INAPPROPRIATE_JSON error.
- Users can consolidate logging from multiple source buckets into a single target bucket. It is recommended to use distinct targetPrefix values for easier differentiation.
- 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.
- If changes to the target bucket or other settings are necessary, send another PutBucketLogging request with the required updates.
- targetPrefix specifies the prefix for object names when saving access logs. It can be null. If not, it should start with a letter and can include letters, numbers, hyphens, underscores, and slashes, with a maximum of 32 characters.
- Repeated requests produce the same response results.
Request URI
PUT /v1/{bucketName}/?logging
| Parameter name | Parameter type | Required or not | Description | Example value | Parameter location |
|---|---|---|---|---|---|
| bucketName | String | Yes | Bucket name xxx | "bucketName_example" | Path |
Parameters of request body
Description of the data structure of request body fields
| Parameter name | Parameter type | Required or not | Description | Example value |
|---|---|---|---|---|
| targetBucket | String | Yes | Specified bucket for storing access logs | TargetBucketName |
| targetPrefix | String | No | Specify the prefix of the ultimately saved access log file. | TargetPrefixName |
Response body parameters
None
Request example
JSON
1PUT /v1/bucketName_example/?logging
2 <Common request headers>
3{
4 "targetPrefix" : "TargetPrefixName",
5 "targetBucket" : "TargetBucketName"
6}
Response example
None
Error code
Please refer to the general error codes
