All Products
Search
Document Center

Object Storage Service:put-bucket-logging

Last Updated:Mar 20, 2026

Enables access logging for an OSS bucket. Once enabled, OSS generates access log objects every hour using predefined naming rules and writes them to the specified destination bucket.

For details on the logging feature, see Logging.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default and must be granted access through RAM Policy or Bucket Policy.

APIActionDescription
PutBucketLoggingoss:PutBucketLoggingEnables logging for a bucket.
PutBucketLoggingoss:PutObjectRequired on the destination bucket when logs are written to a different bucket.

Command syntax

ossutil api put-bucket-logging --bucket <value> --bucket-logging-status <value> [flags]
ParameterTypeDescription
--bucketstringThe name of the source bucket to enable logging for.
--bucket-logging-statusstringThe logging configuration in XML or JSON format. Use the file:// prefix to load the configuration from a file.
This command maps to the PutBucketLogging API operation. For supported global flags, see Command-line options.

Configuration format

The --bucket-logging-status parameter accepts XML or JSON.

XML:

<BucketLoggingStatus>
  <LoggingEnabled>
    <TargetBucket>string</TargetBucket>
    <TargetPrefix>string</TargetPrefix>
  </LoggingEnabled>
</BucketLoggingStatus>

JSON:

{
  "LoggingEnabled": {
    "TargetBucket": "string",
    "TargetPrefix": "string"
  }
}
FieldDescription
TargetBucketThe bucket where OSS stores the access log objects.
TargetPrefixThe prefix added to each log object name, used to organize logs within the destination bucket.

Examples

The following examples enable logging for examplebucket, storing access logs in dest-bucket with the prefix MyLog-.

Enable logging using an XML configuration file

  1. Create a file named bucket-logging-status.xml:

       <?xml version="1.0" encoding="UTF-8"?>
       <BucketLoggingStatus>
         <LoggingEnabled>
           <TargetBucket>dest-bucket</TargetBucket>
           <TargetPrefix>MyLog-</TargetPrefix>
         </LoggingEnabled>
       </BucketLoggingStatus>
  2. Run the command:

       ossutil api put-bucket-logging --bucket examplebucket --bucket-logging-status file://bucket-logging-status.xml

Enable logging using a JSON configuration file

  1. Create a file named bucket-logging-status.json:

       {
         "LoggingEnabled": {
           "TargetBucket": "destBucket",
           "TargetPrefix": "MyLog-"
         }
       }
  2. Run the command:

       ossutil api put-bucket-logging --bucket examplebucket --bucket-logging-status file://bucket-logging-status.json

Enable logging with an inline JSON string

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