Updated on 2026-07-27 GMT+08:00

Configuring Logging for a Bucket

Function

By default, bucket logging is disabled when you create or access a bucket. You can enable bucket logging by turning on the log configuration management switch. OBS logs all the requests for the bucket and stores the logs either in the logged bucket or another bucket that belongs to the same account and region as the logged bucket. You can search and analyze these logs to trace and locate abnormal events. For more information about bucket logging, see Configuring Logging for a Bucket.

Constraints

  • You can store logs in the logged bucket or another bucket. However, the log storage bucket and logged bucket must belong to the same account and region.
  • By default, buckets in the Infrequent Access or Archive storage class cannot be used to store log files. Stored log files occupy storage space in the bucket and are billed the same way as user-stored data.

Authorization

Authorization required for calling this API

To call this API, you must be the bucket owner or have the permission to configure logging for a bucket. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.

  • If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
    • If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you must have the obs:bucket:PutBucketLogging permission. For details, see Creating a Custom IAM Policy.
    • If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you must have the obs:bucket:putBucketLogging permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.

      Action

      Access Level

      Resource Type (*: Required)

      Condition Key

      Alias

      Dependencies

      obs:bucket:putBucketLogging

      Write

      bucket *

      -

      -

      -

      • obs:EpochTime
      • obs:SourceIp
      • obs:TlsVersion
      • obs:CustomDomain
  • If you use bucket policies for authorization, you must have the obs:bucket:PutBucketLogging permission. For details, see Creating a Custom Bucket Policy.

URI

PUT /

Calling Method

For details, see Calling APIs. Before calling this API, calculate the API signature and add it to the request.

You can debug this API in API Explorer.

Request Syntax

The following is an example request. Replace BucketName with your bucket name and RegionID with the ID of the region where your bucket resides. You can obtain the region ID by referring to Supported Regions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
PUT /?logging HTTP/1.1 
Host: BucketName.obs.RegionID.myhuaweicloud.com 
Date: GMT Date
Authorization: SignatureValue
<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus>
  <Agency>agency-name</Agency>
  <LoggingEnabled>
    <TargetBucket>mybucketlogs</TargetBucket>
    <TargetPrefix>mybucket-access_log-/</TargetPrefix>
        <TargetGrants>
      <Grant>
        <Grantee>
          <ID>domainID</ID>
        </Grantee>
        <Permission>READ</Permission>
      </Grant>
    </TargetGrants>
  </LoggingEnabled>
</BucketLoggingStatus>

URI Parameters

Table 1 URI parameters

Parameter

Type

Mandatory

Description

logging

String

No

Definition

An identifier that marks this API as related to bucket logging.

Constraints

N/A

Range

logging

Default Value

N/A

Request Headers

This request uses common headers. For details, see Table 3.

Request Body

Table 2 Request body parameters

Element

Type

Mandatory

Description

BucketLoggingStatus

Container

Yes

Definition

Container for logging status information. If BucketLoggingStatus is empty, bucket logging is disabled.

Constraints

N/A

Range

N/A

Default Value

N/A

Agency

String

Yes if you enable logging for the bucket.

Do not set this parameter when you disable logging for the bucket.

Definition

Name of the IAM agency created by the owner of the target bucket on IAM. For details about how to create an agency, see Creating an Agency.

Constraints

The agency must be a cloud service agency for OBS and the delegated party must have the obs:bucket:PutBucketLogging permission.

Range

N/A

Default Value

N/A

LoggingEnabled

Container

Yes if you enable logging for the bucket.

Do not set this parameter when you disable logging for the bucket.

Definition

Container for logging information. Include this element when logging needs to be enabled. Otherwise, omit it. You can add specific logging information in this element.

Constraints

N/A

Range

N/A

Default Value

N/A

Grant

Container

No

Definition

Container for the grantee and the granted permissions. It describes who has the permission to access the generated log files.

Constraints

N/A

Range

N/A

Default Value

N/A

Grantee

Container

No

Definition

Container for the user who is granted the logging permission.

Constraints

N/A

Range

N/A

Default Value

N/A

ID

String

No

Definition

Account ID of the authorized user, which is globally unique.

Constraints

N/A

Range

N/A

Default Value

N/A

Permission

String

No

Definition

Permissions of the grantee to the generated logs.

Constraints

N/A

Range

  • READ: grants the permission to obtain the bucket objects and bucket metadata.
  • WRITE: grants the permission to upload objects to the bucket. It allows authorized users to delete and overwrite existing objects in the bucket.
  • FULL_CONTROL: grants the permission to fully read, write, and delete objects in the bucket.

Default Value

N/A

TargetBucket

String

Yes if you enable logging for the bucket.

Do not set this parameter when you disable logging for the bucket.

Definition

Name of the bucket where logs are stored. When enabling the logging function, the owner of the bucket being logged can specify a target bucket to store the generated log files.

Constraints

  • Ensure that the bucket owner who configures the logging function has the FULL_CONTROL permission for the bucket that stores log files.
  • If you want to store logs generated by multiple buckets in the same target bucket, you need to specify different TargetPrefix values to identify logs from different source buckets.

Range

N/A

Default Value

N/A

TargetPrefix

String

Yes if you enable logging for the bucket.

Do not set this parameter when you disable logging for the bucket.

Definition

You can specify a prefix using this element so that log files are named with this prefix.

Constraints

N/A

Range

It can contain a maximum of 254 bytes.

Default Value

N/A

TargetGrants

Container

No

Definition

Container for the authorization information.

Constraints

N/A

Range

N/A

Default Value

N/A

Naming Rules for Access Log Objects

1
<TargetPrefix>YYYY-mm-DD-HH-MM-SS-<UniqueString>
  • <TargetPrefix> is a user-defined prefix for log file names, corresponding to the TargetPrefix element in the request body.
    • If <TargetPrefix> ends with /, log files that you can see on the console are stored in the <TargetPrefix> folder, and log file names are in the format of YYYY-mm-DD-HH-MM-SS-<UniqueString>. OBS does not have the concept of folders, so it simulates folders by adding slashes (/) to object names. Therefore, API calls display full object names <TargetPrefix>YYYY-mm-DD-HH-MM-SS-<UniqueString> as log file names.

      Example object name:

      1
      bucket-log/2015-06-29-12-22-07-N7MXLAF1BDG7MPDV
      
      • bucket-log/ is the user-defined prefix.
      • 2015-06-29-12-22-07 is the log generation timestamp.
      • N7MXLAF1BDG7MPDV is a string auto-generated by OBS.
    • If <TargetPrefix> does not end with /, log files that you see on the console are stored directly in the target bucket's root directory, and log file names are in the format of <TargetPrefix>YYYY-mm-DD-HH-MM-SS-<UniqueString>. API calls still display full object names <TargetPrefix>YYYY-mm-DD-HH-MM-SS-<UniqueString> as log file names.

      Example object name:

      1
      bucket-log2015-06-29-12-22-07-N7MXLAF1BDG7MPDV
      
      • bucket-log is the user-defined prefix.
      • 2015-06-29-12-22-07 is the log generation timestamp.
      • N7MXLAF1BDG7MPDV is a string auto-generated by OBS.
  • YYYY-mm-DD-HH-MM-SS indicates the log generation timestamp.
  • <UniqueString> indicates a string auto-generated by OBS.

Bucket Access Log Format

Log entries are space-delimited, with fields containing spaces enclosed in double quotes. The following shows an example access log of the target bucket:

1
787f2f92b20943998a4fe2ab75eb09b8 bucket [13/Aug/2015:01:43:42 +0000] xx.xx.xx.xx 787f2f92b20943998a4fe2ab75eb09b8 281599BACAD9376ECE141B842B94535B  REST.GET.BUCKET.LOCATION - "GET /bucket?location HTTP/1.1" 200 - 211 - 6 6 "-"  "HttpClient" - -  

Each access log contains the following information:

Table 3 Format of bucket access logs

Parameter

Type

Description

BucketOwner

String

Definition

ID of the bucket owner.

Example: 787f2f92b20943998a4fe2ab75eb09b8

Range

The ID can be a tenant ID. For details about how to obtain the ID, see Obtaining Account, IAM User, Project, User Group, Region, and Agency Information.

Bucket

String

Definition

Bucket name.

Example: bucket

Range

The name must meet the bucket naming rules. For details, see Bucket Naming Rules.

Time

String

Definition

Request timestamp in the [dd/MMM/yyyy:HH:mm:ss Z] format.

Example:

[13/Aug/2015:14:43:42 +0000]

Range

The value must be in the [dd/MMM/yyyy:HH:mm:ss Z] format.

Remote IP

String

Definition

Request IP address.

Example:

xx.xx.xx.xx

Range

IPv4: 0.0.0.0 to 255.255.255.255

IPv6: :: to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

Requester

String

Definition

Requester ID.

  • When an account initiates a request, this parameter value is the account ID. When an IAM user initiates a request, this parameter value is the ID of the account where the IAM user belongs.
  • When an anonymous user initiates a request, this parameter value is Anonymous.

Example:

787f2f92b20943998a4fe2ab75eb09b8

Range

The ID can be a tenant ID. For details about how to obtain the ID, see Obtaining Account, IAM User, Project, User Group, Region, and Agency Information.

Anonymous: Anonymous user.

RequestID

String

Definition

Request ID.

Example:

281599BACAD9376ECE141B842B94535B

Range

The value is a string of 32 characters consisting of digits and letters.

Operation

String

Definition

Operation.

Example:

REST.GET.BUCKET.LOCATION

Range

All OBS APIs.

Key

String

Definition

Object name.

Example:

-

Range

The name must meet the object naming rules. For details, see Guidelines on Naming Object Keys.

Request-URI

String

Definition

Request URI in the <HTTP-method> <resource-path><query-parameters> <protocol-version> format.

Example:

GET /bucket?location HTTP/1.1

Range

N/A

HTTPStatus

Integer

Definition

Status code.

Example:

200

Range

Common status codes: [100, 599]

ErrorCode

String

Definition

Error code.

Example:

-

Range

Detailed error code of the request.

BytesSent

Integer

Definition

Size of the HTTP response, expressed in bytes.

Example:

211

Range

[0, ~). The value is determined by the actual response body.

ObjectSize

Integer

Definition

Object size.

Example:

-

Range

The object size cannot be greater than 48 TB.

TotalTime

Integer

Definition

Processing time on the server. Unit: ms

Example:

6

Range

[0, ~). The value is determined by the actual processing time.

Turn-AroundTime

Integer

Definition

Total request processing time.

Unit: ms

Example:

6

Range

[0, ~). The value is determined by the actual processing time.

Referer

String

Definition

Referer header of the request.

Example:

-

Range

The value is the source website address contained in the request header, which is determined by the actual request.

User-Agent

String

Definition

User-Agent header of the request.

Example:

HttpClient

Range

The value is the client ID contained in the request header, which is determined by the actual request.

VersionID

String

Definition

Version ID carried in the request.

Example:

-

Range

  • If versioning is enabled for the bucket, the actual version ID of the object is recorded.
  • If versioning is disabled for the bucket, the default value "-" is recorded.

STSLogUrn

String

Definition

Federated authentication and agency information.

Example:

-

Range

The value must be the requester information. For details about how to obtain the information, see Obtaining Account, IAM User, Project, User Group, Region, and Agency Information.

StorageClass

String

Definition

Current object storage class.

  • STANDARD: Standard storage
  • STANDARD_IA (also WARM): Infrequent Access storage
  • COLD: Archive storage
  • DEEP_ARCHIVE: Deep Archive storage

Example:

STANDARD_IA

Range

  • STANDARD: Standard storage
  • STANDARD_IA (also WARM): Infrequent Access storage
  • COLD: Archive storage
  • DEEP_ARCHIVE: Deep Archive storage

TargetStorageClass

String

Definition

Storage class that the object will be transitioned to.

Example:

GLACIER

Range

This parameter is available only for transitions between storage classes. The value can be:

  • STANDARD: Standard storage
  • STANDARD_IA (also WARM): Infrequent Access storage
  • COLD: Archive storage
  • DEEP_ARCHIVE: Deep Archive storage

DentryName

String

Definition

  • For a parallel file system, this field represents an internal identifier of a file or directory. Its value consists of a parent directory's inode number and a file or directory name and is displayed in the URL-encoded format.

    Example: 12456%2Ffile.txt

  • For a bucket, the value of this field is -.

Range

  • Parallel file system: Internal identifier of a URL-encoded file or directory.
  • Bucket: The value defaults to -.

IAMUserId

String

Definition

ID of an IAM user.

When a request is initiated by an anonymous user, Anonymous is logged.

Example:

8f3b8c53d29244a780084f2b8c106c32

Range

AccessKeyID

String

Definition

Access key ID of the requester. This example value represents an anonymous request.

Example:

UDSIAMSTUBTEST002852

Range

Access key ID of the requester. For anonymous requests, this parameter is -.

Response Syntax

1
2
3
HTTP/1.1 status_code
Date: date
Content-Length: length

Response Headers

This response uses common headers. For details, see Table 1.

Response Body

This response does not contain a response body.

Error Responses

No special errors. You can find all errors in Error Code Overview.

Sample Request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
PUT /?logging HTTP/1.1
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Accept: */*
Date: Wed, 01 Jul 2015 02:40:06 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:mCOjER/L4ZZUY9qr6AOnkEiwvVk=
Content-Length: 528

<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus>
  <Agency>agencyGrantPutLogging</Agency>
  <LoggingEnabled>
    <TargetBucket>log-bucket</TargetBucket>
    <TargetPrefix>mybucket-access_log-/</TargetPrefix>
    
    <TargetGrants>
      <Grant>
        <Grantee>
          <ID>783fc6652cf246c096ea836694f71855</ID>
        </Grantee>
        <Permission>READ</Permission>
      </Grant>
    </TargetGrants>
  </LoggingEnabled>
</BucketLoggingStatus>

Sample Response

1
2
3
4
5
6
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF26000001643663CE53B6AF31C619FD
x-obs-id-2: 32AAAQAAEAABSAAkpAIAABAAAQAAEAABCT9CjuOx8cETSRbqkm35s1dL/tLhRNdZ
Date: Wed, 01 Jul 2015 02:40:06 GMT
Content-Length: 0

Sample Request: Disabling Bucket Log Dump

PUT /?logging HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: Wed, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml

<BucketLoggingStatus>
</BucketLoggingStatus>

Sample Response: Disabling Bucket Log Dump

HTTP/1.1 200 OK
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSalxuWjLa91ewuXRoIcCKZFjFgCrYn0
x-obs-request-id: 0000018A2BC32FB6D2C62C9689DD14B3
Server: OBS
Content-Length: 0
Date: Wed, 01 Jul 2015 02:37:22 GMT

Using SDKs to Call APIs

You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.

Helpful Links