Log management

Last updated: 2020-03-20 11:00:35

PDF

Note

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

func (s *BucketService) PutLogging(ctx context.Context, opt *BucketPutLoggingOptions) (*Response, error)

Request Sample

opt := &cos.BucketPutLoggingOptions{
    LoggingEnabled: &cos.BucketLoggingEnabled{
        TargetBucket: TargetBucket,
    },  
}   
resp, err := client.Bucket.PutLogging(context.Background(), opt)

Parameter description

type BucketLoggingEnabled struct {
    TargetBucket string 
    TargetPrefix string 
}

// BucketPutLoggingOptions is the options of PutBucketLogging
type BucketPutLoggingOptions struct {
    XMLName        xml.Name             
    LoggingEnabled *BucketLoggingEnabled 
}
Parameter name Description Type
BucketPutLoggingOptions Log management configuration parameters Struct
LoggingEnabled Log management configuration Struct
TargetBucket 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
TargetPrefix The log is stored in the designated path of destination bucket. String

Query log management

Function description

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

Method prototype

func (s *BucketService) GetLogging(ctx context.Context) (*BucketGetLoggingResult, *Response, error)

Request Sample

v, resp, err := client.Bucket.GetLogging(context.Background())

Return result description

type BucketGetLoggingResult BucketPutLoggingOptions
Parameter name Description Type
BucketGetLoggingResult Log management configuration parameters Struct
LoggingEnabled Log management configuration Struct
TargetBucket 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
TargetPrefix The log is stored in the designated path of destination bucket. String