edit-icon download-icon

Set logging

Last Updated: Oct 31, 2017

OSS allows you to configure bucket access logging to store the bucket access logs in a specified bucket for future analysis. The logs are stored as objects in the specified bucket. The object name format is as follows:

  1. <TargetPrefix><SourceBucket>-YYYY-mm-DD-HH-MM-SS-UniqueString

The TargetPrefix needs to be specified by the user during configuration.

For more information about access logging, see Bucket Access Logging.

Enable bucket logging

Use putBucketLogging to enable bucket logging:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.putBucketLogging('bucket-name', 'region', 'logs/');
  11. console.log(result);
  12. }).catch(function (err) {
  13. console.log(err);
  14. });

View bucket logging settings

Use getBucketLogging to view bucket logging settings:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.getBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. }).catch(function (err) {
  13. console.log(err);
  14. });

Disable bucket logging

Use deleteBucketLogging to disable bucket logging:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.deleteBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. }).catch(function (err) {
  13. console.log(err);
  14. });
Thank you! We've received your feedback.