PUT Bucket logging

Last updated: 2020-07-03 11:48:50

    Feature description

    This API is used to enable logging for a source bucket and store access logs in a specified destination bucket.

    Only the owner of the source bucket can make this request.
    To enable the access log feature, you need to grant Cloud Log Service (CLS) write permission for COS. For information on the authorization process, see Enabling Log Management.

    Request

    Sample request

    PUT /?logging HTTP 1.1
    Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
    Date: date
    Content-Length: length
    Content-Type: application/xml
    Content-MD5: MD5
    Authorization: Auth String

    Authorization: Auth String (see Request Signature for details).

    Request Headers

    Common Headers

    The implementation of this request requires the use of the Content-MD5 header to verify the integrity of the message, as shown below. For more information on common request headers, see Common Request Headers.

    Name | Description | Type | Required
    |:---|:-- |:--|:--|
    | Content-MD5 | Base64-encoded MD5 hash of the request body content as defined in RFC 1864, used to verify whether the request body underwent changes during transfer | String | Yes |

    Request Body

    The implementation of this request requires a request body. An example of the content of a request body with all nodes is as follows:

    <BucketLoggingStatus>
      <LoggingEnabled>
        <TargetBucket>logbucket</TargetBucket>
        <TargetPrefix>prefix</TargetPrefix>
      </LoggingEnabled>
    </BucketLoggingStatus>

    The specific data descriptions are as follows:

    Node Name (Keyword) Parent Node Description Type Required
    BucketLoggingStatus None Indicates the status of the logging configuration. If there is no child node information, logging is disabled Container Yes

    Content of the Container node BucketLoggingStatus:

    Node Name (Keyword) Parent Node Description Type Required
    LoggingEnabled BucketLoggingStatus Specific bucket logging configuration, mainly for the destination bucket Container No

    Content of the Container node LoggingEnabled:

    Node Name (Keyword) Parent Node Description Type Required
    TargetBucket LoggingEnabled The destination bucket used to store logs; this can be the same bucket (not recommended) or a bucket in the same region under the same account String
    TargetPrefix LoggingEnabled The specified path in which logs are stored in the destination bucket String No

    Response

    Response Header

    This API only returns common response headers. For more information, see Common Response Headers.

    Response Body

    The response body of this response is empty.

    Use Cases

    Request

    PUT /?logging HTTP 1.1
    Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.com
    Date: Fri, 10 Mar 2017 09:45:46 GMT
    Authorization: q-sign-algorithm=sha1&q-ak=AKIDWtTCBYjM5OwLB9CAwA1Qb2ThTSUjfABC&q-sign-time=1484814927;32557710927&q-key-time=1484814927;32557710927&q-header-list=host&q-url-param-list=accelerate&q-signature=8b9f05dabce2578f3a79d732386e7cbade9033e3
    Content-Type: application/xml
    Content-Length: 147
    
    <BucketLoggingStatus>
      <LoggingEnabled>
        <TargetBucket>logbucket</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
    Server: tencent-cos
    x-cos-request-id: NTg4MDdiZWRfOWExZjRlXzQ2OWVfZG==

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help