Enabling Bucket Logging

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

You can call ObsClient.setBucketLogging to enable bucket logging.

The source bucket and target bucket of logging must be in the same region.

If the bucket is in the OBS Infrequent Access or Archive storage class, it cannot be used as the target bucket.

Enabling Bucket Logging

Sample code:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

BucketLoggingConfiguration config = new BucketLoggingConfiguration();
config.setAgency("your agency");
config.setTargetBucketName("targetbucketname");
config.setLogfilePrefix("targetprefix");

obsClient.setBucketLogging("bucketname", config);

Setting ACLs for Objects to Be Logged

Sample code:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

String targetBucket = "targetbucketname"; 

// Configure logging. 
BucketLoggingConfiguration config = new BucketLoggingConfiguration();
config.setAgency("your agency");
config.setTargetBucketName(targetBucket);
config.setLogfilePrefix("prefix");

// Grant the READ permission on the objects to be logged to all users.
GrantAndPermission grant1 = new GrantAndPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
config.setTargetGrants(new GrantAndPermission[]{grant1});

obsClient.setBucketLogging("bucketname", config);