Feature Overview
This document provides an overview of APIs and SDK code samples related to logging.
API | Operation | Description |
Setting Logging | Enables logging for a source bucket | |
Querying log management | Queries the logging configuration of a source bucket |
Setting Logging
Note
This API is used to enable logging for a source bucket and store the access logs in a specified destination bucket.
Note
Only the source bucket owner can request this operation.
Sample Request
Sample 1: configure the source bucket
sourcebucket-1250000000 so that its logs are delivered to the path bucket-logging-prefix/ under the destination bucket targetbucket-1250000000.cos.putBucketLogging({Bucket: 'sourcebucket-1250000000', /* Required */Region: 'ap-beijing', /* Required */BucketLoggingStatus: { /* Required */LoggingEnabled: {TargetBucket: 'targetbucket-1250000000',TargetPrefix: 'bucket-logging-prefix/'}}}, function(err, data) {console.log(err || data);});
Sample 2: disable log delivery to the destination bucket
sourcebucket-1250000000.cos.putBucketLogging({Bucket: 'sourcebucket-1250000000', /* Required */Region: 'ap-beijing', /* Required */BucketLoggingStatus: {} /* Required */}, function(err, data) {console.log(err || data);});
Description
Parameter name | Description | Local Disk Types | Required |
Bucket | The name of the bucket for which to enable logging in the format: BucketName-APPID | String | Required |
Region | String | Required | |
BucketLoggingStatus | Indicates the logging status. If it is empty, logging is disabled. | Object | Required |
- LoggingEnabled | Specifies information on the logging configuration, mainly for the destination bucket | Object | Not required |
- - TargetBucket | Destination bucket that stores logs. It can be the source bucket itself (although this is not recommended), or a bucket in the same account or region as the source bucket. | String | Not required |
- - TargetPrefix | The specified path prefix used to store logs in the destination bucket | String | Not required |
Callback function description
function(err, data) { ... }
Parameter name | Description | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
Querying log management
Note
This API is used to query the logging configuration of a source bucket.
Note
Only the source bucket owner can request this operation.
Sample Request
cos.getBucketLogging({Bucket: 'sourcebucket-1250000000', /* Required */Region: 'ap-beijing' /* Required */}, function(err, data) {console.log(err || data);});
Sample response
{"BucketLoggingStatus": {"LoggingEnabled": {"TargetBucket": "targetbucket-1250000000","TargetPrefix": "bucket-logging-prefix/"}},"statusCode": 200,"headers": {}}
Description
Parameter name | Description | Local Disk Types | Required |
Bucket | The name of the bucket for which to query logging configuration in the format: BucketName-APPID | String | Required |
Region | String | Required |
Callback function description
function(err, data) { ... }
Parameter name | Description | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Data returned when the request is successful. If the request fails, this is null. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
- BucketLoggingStatus | Indicates the logging status. If it is empty, logging is disabled. | Object |
- - LoggingEnabled | Specifies information on the logging configuration, mainly for the destination bucket | Object |
- - - TargetBucket | Destination bucket that stores logs. It can be the source bucket itself (although this is not recommended), or a bucket in the same account or region as the source bucket. | String |
- - - TargetPrefix | The specified path prefix used to store logs in the destination bucket | String |