全部产品
对象存储 OSS

设置访问日志

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

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

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

其中TargetPrefix由用户指定。日志规则由以下2项组成:

  • target_bucket,存放日志文件的Bucket
  • target_prefix,保存访问日志文件前缀

更多关于访问日志的内容请参考 Bucket访问日志

开启Bucket日志

通过OSSClient.setBucketLogging来开启日志功能:

  1. SetBucketLoggingRequest request = new SetBucketLoggingRequest("sourceBucket");
  2. request.setTargetBucket("targetBucket");
  3. request.setTargetPrefix("targetPrefix");
  4. ossClient.setBucketLogging(request);

查看Bucket日志设置

通过OSSClient.getBucketLogging来查看日志设置:

  1. BucketLoggingResult result = ossClient.getBucketLogging("sourceBucket");
  2. System.out.println(result.getTargetBucket());
  3. System.out.println(result.getTargetPrefix());

关闭Bucket日志

通过OSSClient.setBucketLogging来关闭日志功能:

  1. SetBucketLoggingRequest request = new SetBucketLoggingRequest("sourceBucket");
  2. request.setTargetBucket(null);
  3. request.setTargetPrefix(null);
  4. ossClient.setBucketLogging(request);
本文导读目录
本文导读目录
以上内容是否对您有帮助?