Log management

Last updated: 2020-03-20 11:55:18

PDF

Note

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

PutBucketLoggingResult putBucketLogging(PutBucketLoggingRequest request) throws CosXmlClientException, CosXmlServiceException;

void putBucketLoggingAsync(PutBucketLoggingRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String srcBucket = "examplebucket-1250000000"; 
String targetBucket = "examplebucket-1250000000"; 
PutBucketLoggingRequest putBucketLoggingRequest = new PutBucketLoggingRequest(srcBucket);
putBucketLoggingRequest.setTargetBucket(targetBucket);
putBucketLoggingRequest.setTargetPrefix("objectPrefix");

try {
    PutBucketLoggingResult putBucketLoggingResult = cosXmlService.putBucketLogging(putBucketLoggingRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.putBucketLoggingAsync(putBucketLoggingRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        PutBucketLoggingResult putBucketLoggingResult = (PutBucketLoggingResult) result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

Parameter description

Parameter name Description Type
SrcBucket 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

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int

Query log management

Function description

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

Method prototype

GetBucketLoggingResult getBucketLogging(GetBucketLoggingRequest request) throws CosXmlClientException, CosXmlServiceException;

void getBucketLoggingAsync(GetBucketLoggingRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
GetBucketLoggingRequest getBucketLoggingRequest = new GetBucketLoggingRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
getBucketLoggingRequest.setSignParamsAndHeaders(null, headerKeys);
try {
    GetBucketLoggingResult getBucketLoggingResult = cosXmlService.getBucketLogging(getBucketLoggingRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.getBucketLoggingAsync(getBucketLoggingRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        GetBucketLoggingResult getBucketLoggingResult = (GetBucketLoggingResult)result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

Parameter description

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

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int
BucketLoggingStatus Returns Bucket object Logging information BucketLoggingStatus