OSS generates access logs for every request made to your buckets. The log storage feature writes these logs as hourly files to a target bucket using a fixed naming convention.
All examples use the China (Hangzhou) region (cn-hangzhou) with the public endpoint. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead. For the full list of regions and endpoints, see Regions and endpoints for OSS.
Prerequisites
Before you begin, make sure you have:
The required permissions for each operation: To grant these permissions to a RAM user, see Attach a custom policy to a RAM user.
Operation Required permission Enable log storage oss:PutBucketLoggingView log storage configurations oss:GetBucketLoggingDisable log storage oss:DeleteBucketLoggingQuery user-defined log fields oss:GetUserDefinedLogFieldsConfigThe
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables set with your AccessKey pair.
Operations covered
| Operation | API method | Description |
|---|---|---|
| Enable log storage | putBucketLogging | Configures log storage for a bucket and sets the target bucket and prefix for log files |
| View log storage configurations | getBucketLogging | Returns the current log storage configuration for a bucket |
| Disable log storage | deleteBucketLogging | Removes the log storage configuration from a bucket |
| Configure user-defined log fields | putUserDefinedLogFieldsConfig | Sets custom request headers or query parameters to capture in real-time logs |
| Query user-defined log fields | getUserDefinedLogFieldsConfig | Returns the current user-defined log field configuration for a bucket |
| Delete user-defined log fields | deleteUserDefinedLogFieldsConfig | Removes user-defined log field configurations from a bucket |
What's next
PutBucketLogging — API reference for enabling log storage
GetBucketLogging — API reference for viewing log storage configurations
DeleteBucketLogging — API reference for disabling log storage
PutUserDefinedLogFieldsConfig — API reference for configuring user-defined log fields
GetUserDefinedLogFieldsConfig — API reference for querying user-defined log fields
DeleteUserDefinedLogFieldsConfig — API reference for deleting user-defined log fields