您可以开启存储空间的访问日志记录功能,开启后对于此存储空间的访问会被记录成日志文件,保存在指定的存储空间中。
日志文件的格式为:
<TargetPrefix><SourceBucket>YYYY-mm-DD-HH-MM-SS-UniqueString
关于访问日志的更多信息,请参见开发指南中的设置访问日志记录。
开启访问日志记录
通过putBucketLogging
来开启存储空间的访问日志记录。
let OSS = require('ali-oss') let client = new OSS({ region: '<Your region>' accessKeyId: '<Your AccessKeyId>', accessKeySecret: '<Your AccessKeySecret>', bucket: '<Your bucket name>' }); async function putBucketLogging () { try { let result = await client.putBucketLogging('bucket-name', 'logs/'); console.log(result) } catch (e) { console.log(e) } } putBucketLogging();
查看访问日志设置
通过getBucketLogging
来查看存储空间的访问日志设置。
let OSS = require('ali-oss') let client = new OSS({ region: '<Your region>' accessKeyId: '<Your AccessKeyId>', accessKeySecret: '<Your AccessKeySecret>', bucket: '<Your bucket name>' }); async function getBucketLogging() { try { let result = await client.getBucketLogging('bucket-name'); console.log(result); } catch (e) { console.log(e); } }) getBucketLogging();
关闭访问日志记录
通过deleteBucketLogging
来关闭存储空间的访问日志记录。
let OSS = require('ali-oss') let client = new OSS({ region: '<Your region>' accessKeyId: '<Your AccessKeyId>', accessKeySecret: '<Your AccessKeySecret>', bucket: '<Your bucket name>' }); async function deleteBucketLogging () { try { let result = await client.deleteBucketLogging('bucket-name'); console.log(result); } catch (e) { console.log(e); } deleteBucketLogging();