A large number of logs are generated when your Object Storage Service (OSS) buckets are accessed. After you enable and configure logging for a bucket, OSS generates log objects every hour in accordance with predefined naming conventions and then stores the log objects in a specified bucket. You can use Alibaba Cloud Log Service or build a Spark cluster to analyze the logs.

Usage notes

  • The source bucket for which logs are generated and the destination bucket in which the logs are stored can be the same or different. However, the destination bucket must belong to the same Alibaba Cloud account in the same region as the source bucket.
  • OSS generates log objects on an hourly basis. However, requests received in an hour may be recorded in the log objects generated for the previous or subsequent hour.
  • Before you disable logging, OSS keeps generating log objects. Delete log objects that you no longer need to reduce your storage costs.

    You can configure lifecycle rules to regularly delete log objects. For more information, see Lifecycle rules based on the last modified time.

  • To ensure the availability of the OSS-HDFS service or prevent data from being contaminated, do not set Log Prefix to .dlsdata/ when you configure logging for a bucket for which the OSS-HDFS service is enabled.

  • Specific fields may be added to the end of OSS logs. We recommend that developers consider potential compatibility issues when they develop log processing tools.

Naming conventions of log objects

The following naming conventions apply to log objects:

<TargetPrefix><SourceBucket>YYYY-mm-DD-HH-MM-SS-UniqueString
Field Description
TargetPrefix The prefix of the log object name.
SourceBucket The name of the source bucket for which the access logs are generated.
YYYY-mm-DD-HH-MM-SS The time when the log object was created. The items of this field indicate the year, month, day, hour, minute, and second in sequence.
UniqueString The string generated by OSS to uniquely identify the log object.

Log formats and examples

  • Log formats

    OSS access logs include the information about the requester and accessed resources in the following format:

    RemoteIP Reserved Reserved Time "RequestURL" HTTPStatus SentBytes RequestTime "Referer" "UserAgent" "HostName" "RequestID" "LoggingFlag" "RequesterAliyunID" "Operation" "BucketName" "ObjectName" ObjectSize ServerCostTime "ErrorCode RequestLength "UserID" DeltaDataSize "SyncRequest" "StorageClass" "TargetStorageClass" "TransmissionAccelerationAccessPoint" "AccessKeyID"
    Field Example Description
    RemoteIP 192.168.0.1 The IP address of the requester.
    Reserved - The reserved field. It is automatically set to - and cannot be modified.
    Reserved - The reserved field. It is automatically set to - and cannot be modified.
    Time 03/Jan/2021:14:59:49 +0800 The time when OSS received an access request.
    RequestURL GET /example.jpg HTTP/1.0 The request URL that contains a query string.

    OSS ignores the query string parameter that starts with x-. However, this parameter is recorded in logs. Therefore, you can tag a request by using a query string parameter that starts with x-. Then, you can use this tag to query the log corresponding to the request.

    HTTPStatus 200 The HTTP status code that OSS returns.
    SentBytes 999131 The downstream traffic that is generated by the request. Unit: byte.
    RequestTime 127 The amount of time consumed to send the request. Unit: milliseconds.
    Referer http://www.aliyun.com/product/oss The Rerferer header in the HTTP request.
    UserAgent curl/7.15.5 The User-Agent header in the HTTP request.
    HostName examplebucket.oss-cn-hangzhou.aliyuncs.com The destination domain name that the request attempts to access.
    RequestID 5FF16B65F05BC932307A3C3C The ID of the request.
    LoggingFlag true Indicates whether logging is enabled. Valid values:
    • true: Logging is enabled.
    • false: Logging is disabled.
    RequesterAliyunID 16571836914537**** The user ID of the requester. A value of - indicates anonymous access.
    Operation GetObject The type of the request.
    BucketName examplebucket The name of the destination bucket that the request attempts to access.
    ObjectName example.jpg The name of the destination object that the request attempts to access.
    ObjectSize 999131 The size of the destination object. Unit: byte.
    ServerCostTime 88 The time that OSS takes to process the request. Unit: milliseconds.
    ErrorCode - The error code that OSS returns. A value of - indicates that no error code is returned.
    RequestLength 302 The length of the request. Unit: byte.
    UserID 16571836914537**** The ID of the bucket owner.
    DeltaDataSize - The size change of the object. A value of - indicates that this request does not involve write operations on objects.
    SyncRequest cdn Indicates whether the request is an Alibaba Cloud Content Delivery Network (CDN) back-to-origin request. Valid values:
    • cdn: The request is a CDN back-to-origin request.
    • -: The request is not a CDN back-to-origin request.
    StorageClass Standard The storage class of the destination object. Valid values:
    • Standard
    • IA
    • Archive
    • Cold Archive
    • -: The storage class of the object is not obtained.
    TargetStorageClass - Indicates whether the storage class of the object is converted based on a lifecycle rule or the CopyObject operation. Valid values:
    • Standard
    • IA
    • Archive
    • Cold Archive
    • -: The storage class of the object is not converted based on the request.
    TransmissionAccelerationAccessPoint - The acceleration endpoint used when transfer acceleration is used to access the destination bucket. For example, if the requester attempts to access the bucket by using an acceleration endpoint in the China (Hangzhou) region, the value of TransmissionAccelerationAccessPoint is cn-hangzhou.

    A value of - indicates that no acceleration endpoint is used or the acceleration endpoint is in the same region as the destination bucket.

    AccessKeyID LTAI4FrfJPUSoKm4JHb5**** The AccessKey ID of the requester. A value of - indicates anonymous requests.
  • Sample logs
    192.168.0.1 - - [03/Jan/2021:14:59:49 +0800] "GET /example.jpg HTTP/1.0" 200 999131 127 "http://www.aliyun.com/product/oss" "curl/7.15.5" "examplebucket.oss-cn-hangzhou.aliyuncs.com" "5FF16B65F05BC932307A3C3C" "true" "16571836914537****" "GetObject" "examplebucket" "example.jpg" 999131 88 "-" 302 "16571836914537****" - "cdn" "standard" "-" "-" "LTAI4FrfJPUSoKm4JHb5****"

    After the log objects are stored in the specified bucket in OSS, you can use Alibaba Cloud Log Service to analyze the log objects. Before you analyze the log objects, you must import the log objects to Alibaba Cloud Log Service. For more information about how to import data, see Import data from OSS to Log Service. For more information about the analysis feature of Log Service, see Log analysis overview.

Use the OSS console

  1. Log on to the OSS console.
  2. In the left-side navigation pane, click Buckets. On the Buckets page, click the name of the bucket for which you want to configure logging.
  3. In the left-side navigation pane, choose Logging > Logging.
  4. Click Configure. Set Destination Bucket and Log Prefix.
    • Destination Bucket: Select a bucket name from the Destination Bucket drop-down list. You can only select a bucket that is located in the same region as the bucket for which logging is enabled within the same Alibaba Cloud account.
    • Log Prefix: Enter the path and prefix of the logs. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. For example, if you enter log/ in the Log Prefix field, the log objects are stored in the log/ directory.
  5. Click Save.

Use OSS SDKs

The following code provides examples on how to configure logging by using OSS SDKs for common programming languages. For more information about how to configure logging by using OSS SDKs for other programming languages, see Overview.

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.SetBucketLoggingRequest;

public class Demo {

    public static void main(String[] args) throws Exception {
        // In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
        String accessKeyId = "yourAccessKeyId";
        String accessKeySecret = "yourAccessKeySecret";
        // Specify the name of the bucket for which you want to enable logging. Example: examplebucket. 
        String bucketName = "examplebucket";
        // Specify the destination bucket used to store log objects. The source bucket and the destination bucket can be the same bucket or different buckets. 
        String targetBucketName = "yourTargetBucketName";
        // Set the directory in which log objects are stored to log/. If you specify this directory, log objects are stored in the specified directory of the destination bucket. If you do not specify this directory, log objects are stored in the root directory of the destination bucket. 
        String targetPrefix = "log/";

        // Create an OSSClient instance. 
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        try {
            SetBucketLoggingRequest request = new SetBucketLoggingRequest(bucketName);
            request.setTargetBucket(targetBucketName);
            request.setTargetPrefix(targetPrefix);
            ossClient.setBucketLogging(request);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\OssClient;
use OSS\Core\OssException;

// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
$accessKeyId = "yourAccessKeyId";
$accessKeySecret = "yourAccessKeySecret";
// Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
$endpoint = "yourEndpoint";
// Specify the name of the bucket for which you want to enable logging. Example: examplebucket. 
$bucket= "examplebucket";

$option = array();
// Specify the destination bucket used to store the log objects. 
$targetBucket = "destbucket";
// Specify the directory in which the log objects are stored. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. 
$targetPrefix = "log/";

try {
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);

    // Enable logging for the bucket. 
    $ossClient->putBucketLogging($bucket, $targetBucket, $targetPrefix, $option);
} catch (OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");            
const OSS = require('ali-oss')
const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Set yourbucketname to the name of your bucket. 
  bucket: 'yourbucketname'
});
async function putBucketLogging () {
  try {
     const result = await client.putBucketLogging('bucket-name', 'logs/');
     console.log(result)
  } catch (e) {
    console.log(e)
  }
}
putBucketLogging();
# -*- coding: utf-8 -*-
import oss2
from oss2.models import BucketLogging

# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
# Specify the bucket name. Example: examplebucket.     
bucket = oss2.Bucket(auth, 'yourEndpoint', 'examplebucket')

# Specify that the generated log objects are stored in the current bucket. 
# Specify that the log objects are stored in the log/ directory. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. 
# Enable logging for the bucket. 
logging = bucket.put_bucket_logging(BucketLogging(bucket.bucket_name, 'log/'))
if logging.status == 200:
    print("Enable access logging")
else:
    print("request_id:", logging.request_id)
    print("resp:", logging.resp.response)            
using Aliyun.OSS;
using Aliyun.OSS.Common;

// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify the actual endpoint. 
var endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Specify the name of the bucket for which you want to enable logging. Example: examplebucket. 
var bucketName = "examplebucket";
// Specify the name of the destination bucket used to store the log objects. The source bucket and the destination bucket can be the same bucket or different buckets. 
var targetBucketName = "destbucket";
// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    // Specify that the log objects are stored in the log/ directory. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. 
    var request = new SetBucketLoggingRequest(bucketName, targetBucketName, "log/");
    // Enable logging for the bucket. 
    client.SetBucketLogging(request);
    Console.WriteLine("Set bucket:{0} Logging succeeded ", bucketName);
}
catch (OssException ex)
{
    Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
        ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
}
catch (Exception ex)
{
    Console.WriteLine("Failed with error info: {0}", ex.Message);
}
PutBucketLoggingRequest request = new PutBucketLoggingRequest();
// Specify the name of the source bucket for which you want to enable logging. 
request.setBucketName("yourSourceBucketName");
// Specify the name of the destination bucket used to store the log objects. 
// The source bucket and the destination bucket must reside in the same region. The source and destination bucket can both be the same bucket or different buckets. 
request.setTargetBucketName("yourTargetBucketName");
// Specify the directory in which the log objects are stored. 
request.setTargetPrefix("<yourTargetPrefix>");

OSSAsyncTask task = oss.asyncPutBucketLogging(request, new OSSCompletedCallback<PutBucketLoggingRequest, PutBucketLoggingResult>() {
    @Override
    public void onSuccess(PutBucketLoggingRequest request, PutBucketLoggingResult result) {
        OSSLog.logInfo("code::"+result.getStatusCode());
    }

    @Override
    public void onFailure(PutBucketLoggingRequest request, ClientException clientException, ServiceException serviceException) {
         OSSLog.logError("error: "+serviceException.getRawMessage());
    }
});
task.waitUntilFinished();
package main

import (
    "fmt"
    "os"
    "github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
    // Create an OSSClient instance. 
    // Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify the actual endpoint. 
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
    client, err := oss.New("yourEndpoint", "yourAccessKeyId", "yourAccessKeySecret") 
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
    // Specify the name of the bucket for which you want to enable logging. Example: examplebucket. 
    bucketName := "examplebucket"
    // Specify the name of the destination bucket used to store the log objects. The source bucket and the destination bucket can be the same bucket or different buckets. 
    targetBucketName := "destbucket"
    // Specify that the log objects are stored in the log/ directory. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. 
    targetPrefix := "log/"

    // Enable logging for the bucket. 
    err = client.SetBucketLogging(bucketName, targetBucketName, targetPrefix, true)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
}            
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /* Initialize the information about the account that is used to access Object Storage Service (OSS). */
    /* The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. */
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    /* Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
    std::string Endpoint = "yourEndpoint";
    /* Specify the name of the bucket for which you want to enable logging. Example: examplebucket. */
    std::string BucketName = "examplebucket";
    /* Specify the name of the destination bucket used to store the log objects. The source bucket and the destination bucket can be the same bucket or different buckets. */
    std::string TargetBucketName = "destbucket";
    /* Specify that the log objects are stored in the log/ directory. If you specify this parameter, log objects are stored in a specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. */
    std::string TargetPrefix  ="log/";

    /* Initialize resources such as networks. */
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret ,  conf);  

    /* Enable logging for the bucket. */
    SetBucketLoggingRequest request(BucketName, TargetBucketName, TargetPrefix);
    auto outcome = client.SetBucketLogging(request);

    if (!outcome.isSuccess()) {
        /* Handle exceptions. */
        std::cout << "SetBucketLogging fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        ShutdownSdk();
        return -1;
    }

    /* Release resources such as networks. */
    ShutdownSdk();
    return 0;
}
#include "oss_api.h"
#include "aos_http_io.h"
/* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. */
const char *access_key_id = "yourAccessKeyId";
const char *access_key_secret = "yourAccessKeySecret";
/* Specify the bucket name. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Specify the name of the destination bucket in which the log objects are stored. The source bucket and the destination bucket can be the same or different. */
const char *target_bucket_name = "yourTargetBucketName";
/* Specify the directory in which the log objects are stored. If you specify this parameter, the log objects are stored in the specified directory of the destination bucket. If you do not specify this parameter, the log objects are stored in the root directory of the destination bucket. */
const char *target_logging_prefix = "yourTargetPrefix";
void init_options(oss_request_options_t *options)
{
    options->config = oss_config_create(options->pool);
    /* Use a char* string to initialize the aos_string_t data type. */
    aos_str_set(&options->config->endpoint, endpoint);
    aos_str_set(&options->config->access_key_id, access_key_id);
    aos_str_set(&options->config->access_key_secret, access_key_secret);
    /* Specify whether to use CNAME. A value of 0 indicates that CNAME is not used. */
    options->config->is_cname = 0;
    /* Configure network parameters such as the timeout period. */
    options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
    /* Call the aos_http_io_initialize method in main() to initialize global resources such as networks and memory. */
    if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
        exit(1);
    }
    /* Create a memory pool to manage memory. aos_pool_t is equivalent to apr_pool_t. The code used to create a memory pool is included in the APR library. */
    aos_pool_t *pool;
    /* Create a memory pool. The value of the second parameter is NULL. This value indicates that the pool does not inherit other memory pools. */
    aos_pool_create(&pool, NULL);
    /* Create and initialize options. This parameter includes global configuration information such as endpoint, access_key_id, access_key_secret, is_cname, and curl. */
    oss_request_options_t *oss_client_options;
    /* Allocate the memory resources in the memory pool to the options. */
    oss_client_options = oss_request_options_create(pool);
    /* Initialize oss_client_options. */
    init_options(oss_client_options);
    /* Initialize the parameters. */
    aos_string_t bucket;
    oss_logging_config_content_t *content;
    aos_table_t *resp_headers = NULL; 
    aos_status_t *resp_status = NULL; 
    aos_str_set(&bucket, bucket_name);
    content = oss_create_logging_rule_content(pool);
    aos_str_set(&content->target_bucket, target_bucket_name);
    aos_str_set(&content->prefix, target_logging_prefix);
    /* Enable logging for the source bucket. */
    resp_status = oss_put_bucket_logging(oss_client_options, &bucket, content, &resp_headers);
    if (aos_status_is_ok(resp_status)) {
        printf("put symlink succeeded\n");
    } else {
        printf("put symlink failed, code:%d, error_code:%s, error_msg:%s, request_id:%s\n",
            resp_status->code, resp_status->error_code, resp_status->error_msg, resp_status->req_id); 
    }
    /* Release the memory pool. This operation releases the memory resources allocated for the request. */
    aos_pool_destroy(pool);
    /* Release the allocated global resources. */
    aos_http_io_deinitialize();
    return 0;
}
require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
# Specify the bucket name. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')
# Set logging_bucket to the destination bucket in which log objects are stored. 
# Set my-log to the directory in which log objects are stored. If you specify this parameter, log objects are stored in the specified directory of the destination bucket. If you do not specify this parameter, log objects are stored in the root directory of the destination bucket. 
bucket.logging = BucketLogging.new(
  enable: true, target_bucket: 'logging_bucket', target_prefix: 'my-log')

Use ossutil

For more information about how to configure logging by using ossutil, see Enable logging for a bucket.

Use the RESTful API

If your business requires a high level of customization, you can directly call RESTful APIs. To directly call an API, you must include the signature calculation in your code. For more information, see PutBucketLogging.

FAQ

Can I query interrupted requests in OSS access logs?

No, OSS does not record interrupted requests in access logs. If you send a request by using an SDK, you can identify the cause of request interruptions based on the value returned by the SDK.