Set Bucket Logging

By default, buckets do not have logging enabled. To set or modify logging configuration for an existing bucket you make a PUT request that is scoped to the bucket and you use the logging query string parameter. You must include an XML document in the request body that contains the logging configuration. Notice that you cannot set logging configuration on a new bucket that you are creating.

You must have FULL_CONTROL permission to set or modify logging configuration for an existing bucket. Also, you must be authenticated to use the PUT Bucket method.

Query string parameters

Parameter Description Required
logging You use this to change the logging configuration on an existing bucket. You must provide the Logging document in the request body. No

Request headers

See common request headers.

Request body elements

The following request body elements are applicable only if you use the logging query string parameter to specify logging configuration for an existing bucket.

Element Description
Logging Container for logging configuration. Use an empty element (for example, <Logging/>) to disable logging for the bucket.
LogBucket The bucket that will receive log objects. Must be a valid bucket name. Required.
LogObjectPrefix The object prefix for log objects. It can be at most 900 characters and must be a valid object name. Optional.

Request syntax

PUT /?logging HTTP/1.1
Host: <bucket>.storage.googleapis.com
Date: <date and time of the request>
Content-Length: <request body length>
Content-Type: <MIME type of the body>
Authorization: <authentication string>

<xml_document_defining_logging>

Response headers

The request can return a variety of response headers depending on the request headers you use.

Response body elements

The response does not include an XML document in the response body.

Example

The following sample enables Logging for a bucket named example.com.

Request

PUT /example.com?logging HTTP/1.1
Host: storage.googleapis.com
Content-Length: 131
Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg

<Logging>
    <LogBucket>
        logs-bucket
    </LogBucket>
    <LogObjectPrefix>
        my-logs-enabled-bucket
    </LogObjectPrefix>
</Logging>

Response

HTTP/1.1 200 OK
Date: Thu, 12 Mar 2012 03:38:42 GMT
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 0
Content-Type: text/html

Send feedback about...

Cloud Storage Documentation