Feature Overview
This document provides an overview of APIs and SDK code samples related to logging.
API | Operation | Description |
Setting log management | Enables logging for a source bucket | |
Querying log management | Queries the logging configuration of a source bucket |
SDK API References
Setting log management
Note
This API is used to enable logging for a source bucket and store the access logs in a specified destination bucket.
Sample code
Objective-C
QCloudPutBucketLoggingRequest *request = [QCloudPutBucketLoggingRequest new];// Status of the logging configuration. If there is no subnode information, logging is disabledQCloudBucketLoggingStatus *status = [QCloudBucketLoggingStatus new];// Specific logging configuration; this mainly refers to the destination bucketQCloudLoggingEnabled *loggingEnabled = [QCloudLoggingEnabled new];// Destination bucket for storing logs; this can be the source bucket (not recommended) or a bucket in the same region under the same accountloggingEnabled.targetBucket = @"examplebucket-1250000000";// Specified path in the destination bucket for storing logsloggingEnabled.targetPrefix = @"mylogs";status.loggingEnabled = loggingEnabled;request.bucketLoggingStatus = status;// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains all response HTTP headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketLogging:request];
Note
Swift
let req = QCloudPutBucketLoggingRequest.init();// Status of the logging configuration. If there is no subnode information, logging is disabledlet status = QCloudBucketLoggingStatus.init();// Specific logging configuration; this mainly refers to the destination bucketlet loggingEnabled = QCloudLoggingEnabled.init();// Destination bucket for storing logs; this can be the source bucket (not recommended) or a bucket in the same region under the same account// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketloggingEnabled.targetBucket = "examplebucket-1250000000";// Specified path in the destination bucket for storing logsloggingEnabled.targetPrefix = "logs/";status.loggingEnabled = loggingEnabled;req.bucketLoggingStatus = status;// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketreq.bucket = "examplebucket-1250000000";req.finishBlock = {(result,error) inif let result = result {// The result contains the response header information} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketLogging(req);
Note
Querying log management
Note
This API is used to query the logging configuration of a specified bucket.
Sample code
Objective-C
QCloudGetBucketLoggingRequest *getReq = [QCloudGetBucketLoggingRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketgetReq.bucket = @"examplebucket-1250000000";[getReq setFinishBlock:^(QCloudBucketLoggingStatus * _Nonnull result,NSError * _Nonnull error) {// Log configuration informationQCloudLoggingEnabled *loggingEnabled = result.loggingEnabled;}];[[QCloudCOSXMLService defaultCOSXML]GetBucketLogging:getReq];
Note
Swift
let req = QCloudGetBucketLoggingRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketreq.bucket = "examplebucket-1250000000";req.setFinish { (result, error) inif let result = result {// Log configuration informationlet enabled = result.loggingEnabled} else {print(error!);}};QCloudCOSXMLService.defaultCOSXML().getBucketLogging(req);
Note