Log management

Last updated: 2020-03-20 09:42:44

PDF

This document provides an overview of API on log management and sample SDK code.

API Operation name pedagogical operation
PUT Bucket logging Set up log management Enable logging for source Bucket
GET Bucket logging Query log management Query the log configuration information of the source Bucket

Set up log management

Function description

PUT Bucket logging is used to enable logging for the source Bucket and save the Access log of the source Bucket to the specified destination bucket.

Method prototype

public Guzzle\Service\Resource\Model PutBucketLogging(array $args = array());

Request Sample

try {
    $result = $cosClient->putBucketLogging(array(
        'Bucket' => 'examplebucket-1250000000', 
        'LoggingEnabled' => array(
            'TargetBucket' => 'examplebucket2-1250000000',
            'TargetPrefix' => '', 
        )); 
    print_r($result);
} catch (\Exception $e) {
    echo($e);
}

Parameter description

Parameter name Description Type
Bucket Enable the source bucket of log function in BucketName-APPID format. For more information, please see Naming convention String
TargetBucket Destination bucket who stores the log in BucketName-APPID format. For more information, please see Naming convention String
TargetPrefix The log is stored in the designated path of destination bucket. String

Query log management

Function description

GET Bucket logging is used to query the log configuration information of the specified Bucket.

Method prototype

public Guzzle\Service\Resource\Model GetBucketLogging(array $args = array());

Request Sample

try {
    $result = $cosClient->getBucketLogging(array(
        'Bucket' => 'examplebucket-1250000000', 
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo($e);
}

Parameter description

Parameter name Description Type
Bucket Source Bucket in BucketName-APPID format. For more information, please see Naming convention String

Return an example of the result

GuzzleHttp\Command\Result Object
(
    [LoggingEnabled] => Array
        (
            [TargetBucket] => examplebucket2-1250000000
            [TargetPrefix] => 
        )

    [RequestId] => NWRmMWJjOThfMjZiMjU4NjRfODY4X2ExMjcy****
)

Return result description

Member variable Description Type
TargetBucket Destination bucket stored in the log String
TargetPrefix Destination bucket path where the log is stored String