put-bucket-logging

Updated at:

The put-bucket-logging command enables log storage for a bucket. It saves Object Storage Service (OSS) access logs as hourly log files to a specified bucket. The log files follow a fixed naming convention.

Before you begin

Before you enable log storage, ensure that you understand the feature. For more information, see Log storage.

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 policies 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 permission is required for the destination bucket.

Command format

ossutil vectors-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 for access log status information.

Note

The put-bucket-logging command corresponds to the PutBucketLogging API operation.

--bucket-logging-status

The --bucket-logging-status option supports JSON syntax. If the value of this option starts with the file:// prefix, the configuration is read from a file.

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

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

Examples

The following examples show how to enable log storage for a bucket named examplebucket. The log file prefix is MyLog-, and the access logs are stored in the examplebucket bucket.

  • You can use a JSON configuration file. The bucket-logging-status.json file contains the following content:

    {
      "BucketLoggingStatus": {
        "LoggingEnabled": {
          "TargetBucket": "examplebucket",
          "TargetPrefix": "MyLog-",
          "LoggingRole": "AliyunOSSLoggingDefaultRole"
        }
      }
    }

    Example command:

    ossutil vectors-api put-bucket-logging --bucket examplebucket --bucket-logging-status file://bucket-logging-status.json
  • You can use JSON configuration parameters. Example command:

    ossutil vectors-api put-bucket-logging --bucket examplebucket --bucket-logging-status "{\"BucketLoggingStatus\":{\"LoggingEnabled\":{\"TargetBucket\":\"examplebucket\",\"TargetPrefix\":\"MyLog-\",\"LoggingRole\":\"AliyunOSSLoggingDefaultRole\"}}}"