阿里雲團隊努力不懈,力求將最新的技術內容更快地以您最熟悉的語言呈現。本文由簡體中文內容自動轉碼而成,過程無人工干預。阿里雲不保證此自動轉碼的準確性、完整性及時效性。因轉碼造成的任何內容錯誤及因此可能帶來的損失,阿里雲概不負責,敬請見諒。本文内容請以簡體中文版本為準。
全部產品
Search
文件中心

設定訪問日誌

更新時間: Oct 30, 2018

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();