Logging via OSS SDK for Go 2.0
Object Storage Service (OSS) generates access logs to record access to resources stored in OSS buckets. After you enable logging for a bucket, OSS generates access logs every hour based on predefined naming rules and then stores the logs in the specified bucket.
Usage notes
The sample code in this topic uses the region ID
cn-hangzhouof the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket from other Alibaba Cloud services in the same region in which the bucket is located, we recommend that you use an internal endpoint. For a list of regions and endpoints for OSS, see Regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials (Go SDK V1).
To enable logging for a bucket, you must have the
oss:PutBucketLoggingpermission. To query the logging settings of a bucket, you must have theoss:GetBucketLoggingpermission. To disable logging for a bucket, you must have theoss:DeleteBucketLoggingpermission. For more information about how to grant permissions, see Grant a custom policy.
Sample code
References
For more information about the API operation that enables logging for a bucket, see PutBucketLogging.
For more information about the API operation that queries the logging settings of a bucket, see GetBucketLogging.
For more information about the API operation that disables logging for a bucket, see DeleteBucketLogging.
For more information about the API operation that configures custom log fields, see PutUserDefinedLogFieldsConfig.
For more information about the API operation that queries custom log field settings, see GetUserDefinedLogFieldsConfig.
For more information about the API operation that deletes custom log field settings, DeleteUserDefinedLogFieldsConfig.