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:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://your-endpoint'
] );
$targetBucketName = 'targetbucketname';

// Configure logging for the bucket.
$resp = $obsClient->setBucketLogging( [
              'Bucket' => 'bucketname',
              'Agency' => 'your agency',
              'LoggingEnabled' => [                           
                     'TargetBucket' => $targetBucketName,
                     'TargetPrefix' => 'prefix',             
              ]
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );

Use the LoggingEnabled parameter to configure logging for a bucket.

Setting ACLs for Objects to Be Logged

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://your-endpoint'
] );

$targetBucketName = 'targetbucketname';

// Configure logging for the bucket.
$resp = $obsClient->setBucketLogging ( [ 
       'Bucket' => 'bucketname',
       'Agency' => 'your agency',
       'LoggingEnabled' => [ 
              'TargetBucket' => $targetBucketName,
              'TargetPrefix' => 'prefix', 
              'TargetGrants' => [
                           // Grant the READ permission on the objects to be logged to all users.
                           [ 
                                  'Grantee' => [ 
                                                'URI' => ObsClient::GroupAllUsers,
                                                'Type' => 'Group' 
                                  ],
                                  'Permission' => ObsClient::PermissionRead
                           ],
              ] 
       ] 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );