All Products
Search
Document Center

Object Storage Service:put-bucket-logging

Last Updated:May 07, 2025

Enables logging for an Object Storage Service (OSS) bucket. After you enable logging, OSS generates access log objects every hour based on predefined naming rules and then stores the objects in the specified bucket.

Usage notes

Before you enable logging, make sure that you understand this feature. For more information, see Logging.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket Policy.

API

Action

Description

PutBucketLogging

oss:PutBucketLogging

Enables logging for a bucket.

oss:PutObject

When enabling logging for a bucket, if the logs are written to another bucket, this operation permission for the destination bucket is required.

Command syntax

ossutil api put-bucket-logging --bucket value --bucket-logging-status value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--bucket-logging-status

string

The container that stores the logging status information.

Note

The put-bucket-logging command is the equivalent of the PutBucketLogging operation. For more information about the API operation, see PutBucketLogging.

--bucket-logging-status

The --bucket-logging-status parameter supports XML and JSON formats. If the value of the parameter starts with "file://", the configurations are loaded from the specified file.

  • XML format:

    <BucketLoggingStatus>
      <LoggingEnabled>
        <TargetBucket>string</TargetBucket>
        <TargetPrefix>string</TargetPrefix>
      </LoggingEnabled>
    </BucketLoggingStatus>
  • JSON format:

    {
      "LoggingEnabled": {
        "TargetBucket": "string",
        "TargetPrefix": "string"
      }
    }
Note

For more information about supported global command-line options, see Command-line options.

Examples

Enable logging for the examplebucket bucket with access logs prefixed by MyLog- and stored in the dest-bucket bucket.

  • Use an XML configuration file (bucket-logging-status.xml in this example)

    <?xml version="1.0" encoding="UTF-8"?>
    <BucketLoggingStatus>
      <LoggingEnabled>
        <TargetBucket>dest-bucket</TargetBucket>
        <TargetPrefix>MyLog-</TargetPrefix>
      </LoggingEnabled>
    </BucketLoggingStatus>

Sample command:

ossutil api put-bucket-logging --bucket examplebucket --bucket-logging-status file://bucket-logging-status.xml
  • Use a JSON configuration file (bucket-logging-status.json in this example)

    {
      "LoggingEnabled": {
        "TargetBucket": "destBucket",
        "TargetPrefix": "MyLog-"
      }
    }

    Sample command:

    ossutil api put-bucket-logging --bucket examplebucket --bucket-logging-status file://bucket-logging-status.json
  • Use JSON parameters in the command line

    ossutil api put-bucket-logging --bucket examplebucket --bucket-logging-status "{\"LoggingEnabled\":{\"TargetBucket\":\"destBucket\",\"TargetPrefix\":\"MyLog-\"}}"