全部产品
对象存储 OSS

设置访问日志

更新时间:2017-06-07 13:26:11   分享:   

OSS允许用户对Bucket设置访问日志记录,设置之后对于Bucket的访问会被记录成日志,日志存储在OSS上由用户指定的Bucket中,文件的格式为:

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

其中TargetPrefix由用户指定。更多关于访问日志的内容请参考 Bucket访问日志

开启Bucket日志

通过putBucketLogging来开启日志功能:

  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. });

查看Bucket日志设置

通过getBucketLogging来查看日志设置:

  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. });

关闭Bucket日志

通过deleteBucketLogging来关闭日志功能:

  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. });
本文导读目录
本文导读目录
以上内容是否对您有帮助?