Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Log storage (Node.js SDK)

Son Güncelleme:Oct 01, 2026

Object Storage Service (OSS) erişim günlükleri, paketlerinize yapılan isteklere ilişkin ayrıntılı bilgileri yakalar. Kaynak paket için günlüklemeyi etkinleştirdiğinizde OSS, önceden tanımlanmış bir adlandırma kuralı kullanarak saatlik olarak günlük dosyalarını belirttiğiniz hedef pakete otomatik olarak oluşturur ve iletir.

Günlük depolamayı etkinleştirin

Aşağıdaki kodda günlük depolamanın nasıl etkinleştirileceği gösterilmektedir.

const OSS = require('ali-oss')
const client = new OSS({
  // Set region to the region where the bucket is located. For example, for China (Hangzhou), set region to oss-cn-hangzhou.
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before running this code sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Set bucket to the name of your bucket.
  bucket: 'yourbucketname'
});
async function putBucketLogging () {
  try {
     const result = await client.putBucketLogging('bucket-name', 'logs/');
     console.log(result)
  } catch (e) {
    console.log(e)
  }
}
putBucketLogging();

Günlük depolama yapılandırmasını görüntüleyin

Aşağıdaki kodda günlük depolama yapılandırmasının nasıl görüntüleneceği gösterilmektedir.

const OSS = require('ali-oss')

const client = new OSS({
  // Set region to the region where the bucket is located. For example, for China (Hangzhou), set region to oss-cn-hangzhou.
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before running this code sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Set bucket to the name of your bucket.
  bucket: 'yourbucketname'
});

async function getBucketLogging() {
  try {
     const result = await client.getBucketLogging('bucket-name');
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

getBucketLogging();

Günlük depolamayı devre dışı bırakın

Aşağıdaki kodda günlük depolama özelliğinin nasıl devre dışı bırakılacağı gösterilmektedir.

const OSS = require('ali-oss')

const client = new OSS({
  // Set region to the region where the bucket is located. For example, for China (Hangzhou), set region to oss-cn-hangzhou.
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before running this code sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Set bucket to the name of your bucket.
  bucket: 'yourbucketname'
});

async function deleteBucketLogging () {
  try {
    const result = await client.deleteBucketLogging('bucket-name');
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

deleteBucketLogging();

İlgili Konular

  • Günlük depolama için tam örnek kodları görmek üzere GitHub örneklerine bakın.

  • Günlük depolamayı etkinleştirmeye yönelik API işlemi hakkında daha fazla bilgi için bkz. PutBucketLogging.

  • Günlük depolama yapılandırmasını görüntülemeye yönelik API işlemi hakkında daha fazla bilgi için bkz. GetBucketLogging.

  • Günlük depolamayı devre dışı bırakmaya yönelik API işlemi hakkında daha fazla bilgi için bkz. DeleteBucketLogging.