全部产品
弹性计算 会员服务 网络 安全 移动云 数加·大数据分析及展现 数加·大数据应用 管理与监控 云通信 阿里云办公 培训与认证 智能硬件 ET大脑
存储与CDN 数据库 域名与网站(万网) 应用服务 数加·人工智能 数加·大数据基础服务 互联网中间件 视频服务 开发者工具 解决方案 物联网 更多
对象存储 OSS

设置访问日志

更新时间:2018-08-08 13:27:11

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

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

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

开启Bucket日志

通过putBucketLogging来开启日志功能:

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

查看Bucket日志设置

通过getBucketLogging来查看日志设置:

  1. let OSS = require('ali-oss')
  2. let client = new OSS({
  3. region: '<Your region>'
  4. accessKeyId: '<Your AccessKeyId>',
  5. accessKeySecret: '<Your AccessKeySecret>',
  6. bucket: '<Your bucket name>'
  7. });
  8. async function getBucketLogging() {
  9. try {
  10. let result = await client.getBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. } catch (e) {
  13. console.log(e);
  14. }
  15. })
  16. getBucketLogging();

关闭Bucket日志

通过deleteBucketLogging来关闭日志功能:

  1. let OSS = require('ali-oss')
  2. let client = new OSS({
  3. region: '<Your region>'
  4. accessKeyId: '<Your AccessKeyId>',
  5. accessKeySecret: '<Your AccessKeySecret>',
  6. bucket: '<Your bucket name>'
  7. });
  8. async function deleteBucketLogging () {
  9. try {
  10. let result = await client.deleteBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. } catch (e) {
  13. console.log(e);
  14. }
  15. deleteBucketLogging();
本文导读目录