Log management

Last updated: 2020-03-20 12:34:27

PDF

Note

This document provides an overview of API on log management and sample C 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

cos_status_t *cos_put_bucket_logging(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_logging_params_t *logging_params,
                                      cos_table_t **resp_headers);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0; 
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_logging_params_t  *params = NULL;
cos_logging_params_t  *result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool); 
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

params = cos_create_logging_params(options->pool);
cos_str_set(&params->target_bucket, TEST_BUCKET_NAME);
cos_str_set(&params->target_prefix, "logging/");

status = cos_put_bucket_logging(options, &bucket, params, &resp_headers);
log_status(status);

cos_pool_destroy(pool); 

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Enable the source bucket of log function in BucketName-APPID format. For more information, please see Naming convention String
Logging_params Bucket log configuration information Struct
Target_bucket The destination bucket who keeps the log can be the same Bucket (but not recommended), or Bucket under the same account and in the same region. String
Target_prefix The log is stored in the designated path of destination bucket. String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String

Query log management

Function description

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

Method prototype

cos_status_t *cos_get_bucket_logging(const cos_request_options_t *options,  
                                      const cos_string_t *bucket,    
                                      cos_logging_params_t *logging_params,
                                      cos_table_t **resp_headers);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0; 
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_logging_params_t  *params = NULL;
cos_logging_params_t  *result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool); 
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

result = cos_create_logging_params(options->pool);
status = cos_get_bucket_logging(options, &bucket, result, &resp_headers);
log_status(status);

if (!cos_status_is_ok(status)) {
    cos_pool_destroy(pool);
    return;
}    

char *line = NULL;
line = apr_psprintf(options->pool, "%.*s\n", result->target_bucket.len, result->target_bucket.data);
printf("target bucket: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", result->target_prefix.len, result->target_prefix.data);
printf("target prefix: %s", line);

cos_pool_destroy(pool); 

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Destination bucket who stores the log in BucketName-APPID format. For more information, please see Naming convention String
Logging_params Bucket log configuration information Struct
Target_bucket The destination bucket who keeps the log can be the same Bucket (but not recommended), or Bucket under the same account and in the same region. String
Target_prefix The log is stored in the designated path of destination bucket. String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String