Description
The PUT Bucket Logging API is used to enable logging for the source bucket to save the access logs of the source bucket into a specified destination bucket.
Note:
- Only the owner of the source bucket can call this API.
- To enable the access logging feature, you need to grant CLS the permission to write data into COS. For the authorization process, see Enable log management.
Request
Request Example
PUT /?logging HTTP 1.1
Host: <BucketName-APPID>.<Endpoint>
Date:date
Content-Length: length
Content-Type: application/xml
Content-MD5: MD5
Authorization: Auth String
Note:
<BucketName-APPID>is the bucket name with APPID as the suffix, for example, examplebucket-1250000000.- Authorization: Auth String (For details, see Request Signature documentation).
Request Header
This API only uses common request headers. For details, see Common Request Headers documentation.
Request Body
A request body is required to implement this request operation. The content of an example request body with all nodes is as follows:
<BucketLoggingStatus>
<LoggingEnabled>
<TargetBucket>examplebucket-1250000000</TargetBucket>
<TargetPrefix>prefix</TargetPrefix>
</LoggingEnabled>
</BucketLoggingStatus>
The data are described as follows:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| BucketLoggingStatus | No | Logging status. If there is no child node information, logging is disabled. | Container | Yes |
Content of the BucketLoggingStatus node of the Container type:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| LoggingEnabled | BucketLoggingStatus | Specific logging settings information of a bucket, mainly the destination bucket. | Container | No |
Content of the LoggingEnabled node of the Container type:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| TargetBucket | LoggingEnabled | Destination bucket for storing logs, which can be the same bucket (not recommended), or a bucket under the same account in the same region. | String | No |
| TargetPrefix | LoggingEnabled | Path in the destination bucket that stores logs. | String | No |
Note:
After you specify the bucket and path for storing logs, the generated log file name is in
Destination bucket/path prefix{YYYY}/{MM}/{DD}/{time}_{random}_{index}.gzformat.
Response
Response Headers
This API only returns the public response header. For details, see Common Response Headers documentation.
Response Body
The response body is empty.
Error Code
This API follows unified error response and error codes. For details, please refer to the Error Codes document.
Practical Case
Request
PUT /?logging HTTP 1.1
Host: <BucketName-APPID>.<Endpoint>
Date: Fri, 10 Mar 2017 09:45:46 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDWtTCBYjM5OwLB9CAwA1Qb2ThTSUj****&q-sign-time=1484814927;32557710927&q-key-time=1484814927;32557710927&q-header-list=host&q-url-param-list=accelerate&q-signature=8b9f05dabce2578f3a79d732386e7cbade90****
Content-Type: application/xml
Content-Length: 147
<BucketLoggingStatus>
<LoggingEnabled>
<TargetBucket>examplebucket-1250000000</TargetBucket>
<TargetPrefix>prefix</TargetPrefix>
</LoggingEnabled>
</BucketLoggingStatus>
Response
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Connection: keep-alive
Date: Fri, 10 Mar 2017 09:45:46 GMT
x-cos-request-id: NTg4MDdiZWRfOWExZjRlXzQ2OWVf****