Log management

Last updated: 2020-08-31 16:25:52

    Overview

    This document provides an overview of APIs and SDK code samples related to logging.

    API Operation Description
    PUT Bucket logging Setting logging Enables logging for a source bucket
    GET Bucket logging Querying logging Queries the logging configuration of a source bucket

    SDK API References

    For the parameters and method descriptions of all the APIs in the SDK, see Api Documentation.

    Setting Logging

    API description

    This API is used to enable logging for a source bucket and store the access logs in a specified destination bucket.

    Sample code

    try
    {
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      PutBucketLoggingRequest request = new PutBucketLoggingRequest(bucket);
      // Set the destination path for storing logs
      request.SetTarget("targetbucket-1250000000", "logs/");
      // Execute the request
      PutBucketLoggingResult result = cosXml.putBucketLogging(request);
      // Request successful 
      Console.WriteLine(result.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      // Request failed
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      // Request failed
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    Note:

    For more samples, please visit GitHub.

    Querying Logging

    API description

    This API is used to query the logging configuration of a specified bucket.

    Sample code

    try
    {
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      GetBucketLoggingRequest request = new GetBucketLoggingRequest(bucket);
      // Execute the request
      GetBucketLoggingResult getResult = cosXml.getBucketLogging(request);
      // Request successful 
      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)
    {
      // Request failed
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      // Request failed
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    Note:

    For more samples, please visit GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help