Enables access logging for the specified Amazon S3 bucket.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
The name of the bucket to enable logging for. Pass a |
|
|
|
Required |
The name of the bucket to store the logs in. |
|
|
|
Required |
The prefix to give to the log file names. |
|
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
|---|---|
|
A |
Examples
Enable logging on a bucket.
// Instantiate the class
$s3 = new AmazonS3();
$logged_bucket = 'my-bucket-test' . strtolower($s3->key);
$logging_bucket = 'my-bucket-logs' . strtolower($s3->key);
// Create bucket for storing logs
$bucket = $s3->create_bucket($logging_bucket, AmazonS3::REGION_US_STANDARD);
// Ensure that the bucket was created successfully...
if ($bucket->isOK())
{
// Enable READ_ACP and WRITE permissions for the system-wide "logging" user.
$acl = $s3->set_bucket_acl($logging_bucket, array(
array( 'id' => AmazonS3::USERS_LOGGING, 'permission' => AmazonS3::GRANT_READ_ACP ), // Logging user, READ_ACP
array( 'id' => AmazonS3::USERS_LOGGING, 'permission' => AmazonS3::GRANT_WRITE ), // Logging user, WRITE
array( 'id' => CFCredentials::get()->canonical_id, 'permission' => AmazonS3::GRANT_FULL_CONTROL ), // Self, FULL_CONTROL
));
// Ensure that the ACL was set correctly...
if ($acl->isOK())
{
// Enable logging on the bucket
$response = $s3->enable_logging($logged_bucket, $logging_bucket, 'log_', array(
'users' => array(
array('id' => AmazonS3::USERS_AUTH, 'permission' => AmazonS3::GRANT_READ),
array('id' => AmazonS3::USERS_ALL, 'permission' => AmazonS3::GRANT_READ),
array('id' => AmazonS3::USERS_LOGGING, 'permission' => AmazonS3::GRANT_READ),
array('id' => 'email@domain.com', 'permission' => AmazonS3::GRANT_FULL_CONTROL),
)
));
// Success?
var_dump($response->isOK());
}
}
Result:
bool(true)
See Also
Source
Method defined in services/s3.class.php | Toggle source view (68 lines) | View on GitHub

