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 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 the installation with source code. // require 'obs-autoloader.php'; // Declare the namespace. useObs\ObsClient; // Create an ObsClient instance. $obsClient = new ObsClient ( [ //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint' ] ); $targetBucketName = 'targetbucketname'; // Configure logging for the bucket. $resp = $obsClient -> setBucketLogging( [ 'Bucket' => 'bucketname', // Name of the OBS agency created by the owner of the target bucket on IAM. 'Agency' => 'Agency name', '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 the installation with source code. // require 'obs-autoloader.php'; // Declare the namespace. use Obs\ObsClient; // Create an ObsClient instance. $obsClient = new ObsClient ( [ //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint' ] ); ; $targetBucketName = 'targetbucketname'; // Configure logging for the bucket. $resp = $obsClient->setBucketLogging ( [ 'Bucket' => 'bucketname', // Name of the OBS agency created by the owner of the target bucket on IAM. 'Agency' => 'Agency name', 'LoggingEnabled' => [ 'TargetBucket' => $targetBucketName, 'TargetPrefix' => 'prefix', 'TargetGrants' => [ // Grant all users the READ permission on the logs. [ 'Grantee' => [ 'URI' => ObsClient::GroupAllUsers, 'Type' => 'Group' ], 'Permission' => ObsClient::PermissionRead ], ] ] ] ); printf ( "RequestId:%s\n", $resp ['RequestId'] );
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.