• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Bucket-Related APIs
  5. PUT Bucket logging

PUT Bucket logging

API Description

You can use this API to set logging for a bucket. Ensure that the log delivery user group of the target bucket has WRITE and READ_ACP permissions. (For details, see PUT Bucket acl.)

Method Definition

ObsClient.setBucketLoggingConfiguration(bucketName, logstatus)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

logstatus

Logging

Optional

Log configuration information

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.grantee import Grantee 
    from com.obs.models.grant import Grant 
    from com.obs.models.logging import Logging 
     
    grantee1 = Grantee(grantee_id='userid', grantee_name='username', group=None) 
     
    grantee2 = Grantee(group='http://acs.amazonaws.com/groups/global/AllUsers') 
     
    grant1 = Grant(grantee=grantee1, permission='WRITE') 
    grant2 = Grant(grantee=grantee2, permission='READ') 
     
    grantList = [grant1, grant2] 
    logstatus = Logging(targetBucket='targetbucketname', targetPrefix='prefix', targetGrants=grantList) 
     
    resp = obsClient.setBucketLoggingConfiguration('bucketname', logstatus) 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())