Log management

Last updated: 2020-03-20 10:19:20

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);

void putBucketLoggingAsync(PutBucketLoggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;         
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  PutBucketLoggingRequest request = new PutBucketLoggingRequest(bucket);
  request.SetTarget("targetbucket-1250000000", "/abc");
  request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
  PutBucketLoggingResult result = cosXml.putBucketLogging(request);
  Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

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
Prefix The log is stored in the designated path of destination bucket. String

Return result description

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

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);

void getBucketLoggingAsync(GetBucketLoggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000) 
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;         
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  GetBucketLoggingRequest request = new GetBucketLoggingRequest(bucket);
  request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
  GetBucketLoggingResult result = cosXml.getBucketLogging(request);
  BucketLoggingStatus status = getResult.bucketLoggingStatus;
  if (status != null && status.loggingEnabled != null) {
    string targetBucket = status.loggingEnabled.targetBucket;
    string targetPrefix = status.loggingEnabled.targetPrefix;
  }
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

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
TargetBucket Destination bucket of log storage String
TargetPrefix Destination bucket path of log storage String