A large number of logs are generated when Object Storage Service (OSS) resources are accessed. After you enable and configure logging for a bucket, OSS generates log objects every hour based on 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 bucket or different buckets. However, the destination bucket must belong to the same Alibaba Cloud account and reside in the same region as the source bucket.
  • Log objects for a given period are generated within a few hours. Requests received in an hour may be recorded in the log objects generated for the previous or subsequent hour. Therefore, the log objects that are generated in a given period cannot provide complete and real-time logging for that period of time.
  • Before you disable logging, OSS continuously generates log objects every hour. We recommend that you delete log objects that you no longer need to reduce storage costs.

    You can configure lifecycle rules to periodically 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.

  • OSS adds specific fields to the end of logs. We recommend that you consider potential compatibility issues when you 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
FieldDescription
TargetPrefixThe prefix of the log object name.
SourceBucketThe name of the source bucket for which the access logs are generated.
YYYY-mm-DD-HH-MM-SSThe time when the log object was created. The items of this field indicate the year, month, day, hour, minute, and second in sequence.
UniqueStringThe string generated by OSS to uniquely identify the log object.

Log formats and examples

  • Log formats

    OSS access logs include information about the requester and the 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"
    FieldExampleDescription
    RemoteIP192.168.0.1The IP address of the requester.
    Reserved-The reserved field. Retain the default value -.
    Reserved-The reserved field. Retain the default value -.
    Time03/Jan/2021:14:59:49 +0800The point in time when OSS received the access request.
    RequestURLGET /example.jpg HTTP/1.0The 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 that corresponds to the request.

    HTTPStatus200The HTTP status code that is returned by OSS.
    SentBytes999131The outbound traffic generated by the request. Unit: bytes.
    RequestTime127The amount of time taken by the request. Unit: milliseconds.
    Refererhttp://www.aliyun.com/product/ossThe Referer header in the HTTP request.
    UserAgentcurl/7.15.5The User-Agent header in the HTTP request.
    HostNameexamplebucket.oss-cn-hangzhou.aliyuncs.comThe domain name that the requester wants to access.
    RequestID5FF16B65F05BC932307A3C3CThe ID of the request.
    LoggingFlagtrueIndicates whether logging is enabled. Valid values:
    • true: Logging is enabled.
    • false: Logging is disabled.
    RequesterAliyunID16571836914537****The user ID of the requester. The value - indicates anonymous access.
    OperationGetObjectThe type of the request.
    BucketNameexamplebucketThe name of the bucket that the requester wants to access.
    ObjectNameexample.jpgThe name of the object that the requester wants to access.
    ObjectSize999131The size of the object that the requester wants to access. Unit: bytes.
    ServerCostTime88The time that is consumed by OSS to process the request. Unit: milliseconds.
    ErrorCode-The error code that is returned by OSS. The value - indicates that no error code is returned.
    RequestLength302The length of the request. Unit: bytes.
    UserID16571836914537****The ID of the bucket owner.
    DeltaDataSize-The change in the size of an object. The value - indicates that this request does not involve write operations on the object.
    SyncRequestcdnIndicates whether the request is an Alibaba Cloud 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.
    StorageClassStandardThe storage class of the object that the requester wants to access. Valid values:
    • Standard
    • IA
    • Archive
    • Cold Archive
    • -: The storage class of the object is not obtained.
    TargetStorageClass-The storage class of the object after the storage class is converted based on a lifecycle rule or the CopyObject operation. Valid values:
    • Standard
    • IA
    • Archive
    • Cold Archive
    • -: The request does not involve storage class conversion.
    TransmissionAccelerationAccessPoint-The acceleration endpoint that is used when transfer acceleration is enabled to access the destination bucket. For example, if the requester wants to access the bucket by using an acceleration access point in the China (Hangzhou) region, the value of TransmissionAccelerationAccessPoint is cn-hangzhou.

    The value - indicates that no acceleration endpoint is used or the acceleration endpoint is in the same region as the bucket that the requester wants to access.

    AccessKeyIDLTAI4FrfJPUSoKm4JHb5****The AccessKey ID of the requester. The value - indicates anonymous requests.
  • Sample log entry
    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 desired bucket.
  3. In the navigation tree, choose Logging > Logging.
  4. On the Logging tab, turn on Logging, and specify the destination bucket and the directory for log storage.
    • 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 directory that stores logs. 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. 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 sample code provides examples on how to configure logging by using OSS SDKs for common programming languages. For the sample code that is used 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;
        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 = Aliyun::OSS::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 RESTful APIs

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 by using OSS access logs?

No, you cannot. 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 return value of the SDK.