PutBucketLogging
Updated at:2025-11-03
API description
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).
Request
-
Request syntax
Plain Text1 PUT /?logging HTTP/1.1 2 Host: <BucketName>.bj.bcebos.com 3 Date: <Date> 4 Authorization: <AuthorizationString> 5 Content-Length: <ContentLength> 6 { 7 "targetBucket": "TargetBucketName", 8 "targetPrefix": "TargetPrefixName" 9 } -
Request headers
No special parameters
-
Request parameters
| Name | Description | Types | Required or not |
|---|---|---|---|
| targetBucket | Specified bucket for storing access logs | String | Yes |
| targetPrefix | Specify the prefix of the ultimately saved access log file. | String | No (it is recommended that this field should be filled in for distinguishing access logs) |
Response
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 store Logging from different source buckets in the same target bucket. It is recommended that different
targetPrefixshould be specified for easy distinction. - 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.
targetPrefixindicates the prefix of the object name for storing access logs, which can be empty. If not empty,targetPrefix} can contain letters, numbers, hyphens, underscores and slashes, must start with a letter, and be no longer than 32 characters.- Repeated requests produce the same response results.
Example
-
Request example
Plain Text1PUT /?logging HTTP/1.1 2Host: BucketName.bj.bcebos.com 3Date: Tue, 17 May 2016 08:36:52 GMT 4Authorization: AuthorizationString 5Content-Length: 55 6{ 7 "targetBucket": "dscbucket", 8 "targetPrefix": "mylog/" 9} -
Response example
Plain Text1HTTP/1.1 200 OK 2x-bce-request-id: 1a5fd81e-626b-45b3-a885-15fff9cd106c 3Date: Tue, 17 May 2016 08:36:52 GMT 4Content-Length: 0 5Server: BceBos
