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 OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');

// 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',
    Agency: 'your agency'
    LoggingEnabled:{
        TargetBucket: targetBucketName,
        TargetPrefix: 'prefix',
    }
}, (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:

// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');

// 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',
    Agency: 'your agency',
    LoggingEnabled:{
        TargetBucket: targetBucketName,
        TargetPrefix: 'prefix',
        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}
        ]
     }
}, (err, result) => {
    if(err){
        console.log('Error-->' + err);
    }else{
        console.log('Status-->' + result.CommonMsg.Status);
    }
});