Log management

Last updated: 2020-03-20 09:24:49

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

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudPutBucketLoggingRequest
  2. Call the PutBucketLogging method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudPutBucketLoggingRequest *request = [QCloudPutBucketLoggingRequest new];
QCloudBucketLoggingStatus *status = [QCloudBucketLoggingStatus new];
QCloudLoggingEnabled *loggingEnabled = [QCloudLoggingEnabled new];
loggingEnabled.targetBucket = @"examplebucket-1250000000";
loggingEnabled.targetPrefix = @"mylogs";
status.loggingEnabled = loggingEnabled;
request.bucketLoggingStatus = status;
request.bucket = @"examplebucket-1250000000";
[request setFinishBlock:^(id outputObject, NSError *error) {

}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketLogging:request];

Swift code example:

let req = QCloudPutBucketLoggingRequest.init();

let status = QCloudBucketLoggingStatus.init();

let loggingEnabled = QCloudLoggingEnabled.init();

loggingEnabled.targetBucket = "examplebucket-1250000000";

loggingEnabled.targetPrefix = "";
status.loggingEnabled = loggingEnabled;
req.bucketLoggingStatus = status;
req.bucket = "examplebucket-1250000000";
req.finishBlock = {(result,error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
}

QCloudCOSXMLService.defaultCOSXML().putBucketLogging(req);

Parameter description

QCloudPutBucketLoggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Enable the source bucket of log function in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
BucketLoggingStatus Describe the status of the logging configuration QCloudBucketLoggingStatus * Yes

QCloudBucketLoggingStatus parameter description

Parameter name Description Type Required/Optional
LoggingEnabled The specific information of Bucket's logging setting is mainly destination bucket. QCloudLoggingEnabled * Yes

QCloudLoggingEnabled parameter description

Parameter name Description Type Required/Optional
TargetBucket Destination bucket who keeps the diary NSString * Yes
TargetPrefix The log is stored in the designated path of destination bucket. NSString * Yes

Query log management

Function description

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

Method prototype

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudGetBucketLoggingRequest
  2. Call the GetBucketLogging method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudGetBucketLoggingRequest *getReq = [QCloudGetBucketLoggingRequest new];
getReq.bucket = @"examplebucket-1250000000";
[getReq setFinishBlock:^(QCloudBucketLoggingStatus * _Nonnull result, NSError * _Nonnull error) {
    NSLog(@"getReq result = %@",result.loggingEnabled.targetBucket);

}];
[[QCloudCOSXMLService defaultCOSXML]GetBucketLogging:getReq];

Swift code example:

let req = QCloudGetBucketLoggingRequest.init();
req.bucket = "examplebucket-1250000000";
req.setFinish { (result, error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
};
QCloudCOSXMLService.defaultCOSXML().getBucketLogging(req);

Parameter description

QCloudGetBucketLoggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Destination bucket who stores the log in BucketName-APPID format. For more information, please see Naming convention NSString * Yes

Return result description

QCloudBucketLoggingStatus parameter description

Parameter name Description Type
LoggingEnabled The specific information of Bucket's logging setting is mainly destination bucket. QCloudLoggingEnabled *

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.