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:
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'https://your-endpoint'
});
// Configure logging for the bucket.
obsClient.setBucketLogging({
Bucket:'bucketname',
LoggingEnabled:{
TargetBucket: targetBucketName,
TargetPrefix: 'prefix',
Agency: 'your agency'
}
}, function(err, result) {
if(err){
console.log('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
}
});
Use the LoggingEnabled parameter to configure logging for a bucket.
Setting ACLs for Objects to Be Logged
Sample code:
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'https://your-endpoint'
});
// Configure logging for the bucket.
obsClient.setBucketLogging({
Bucket:'bucketname',
LoggingEnabled:{
TargetBucket: targetBucketName,
TargetPrefix: 'prefix',
Agency: 'your agency',
TargetGrants:[
// Grant the READ permission on the objects to be logged to all users.
{Grantee:{Type:'Group',URI:obsClient.enums.GroupAllUsers},Permission:obsClient.enums.PermissionRead},
// Grant the WRITE permission on the log files to all users.
{Grantee:{Type:'Group',URI:obsClient.enums.GroupAllUsers},Permission:obsClient.enums.PermissionWrite}
]
}
}, function(err, result) {
if(err){
console.log('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
}
});
Last Article: Logging Overview
Next Article: Viewing Bucket Logging
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.