Tous les produits
Search
Centre de documentation

Object Storage Service:Stockage des journaux (SDK Ruby)

Dernière mise à jour :Aug 18, 2026

La journalisation des accès Object Storage Service (OSS) capture des informations détaillées sur les requêtes adressées à vos buckets. Une fois la journalisation activée pour un bucket source, OSS génère et livre automatiquement des fichiers de journaux toutes les heures vers un bucket de destination que vous spécifiez, en respectant une convention de nommage prédéfinie.

Activer la journalisation pour un bucket

Utilisez le code suivant pour activer la fonctionnalité de stockage des journaux.

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) region is used as an example for the endpoint. Specify a region as needed.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before running this code, set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Specify the bucket name, for example, examplebucket.
bucket = client.get_bucket('examplebucket')
# Set logging_bucket to the destination bucket for log files.
# Set my-log to the folder where log files are stored. If you specify this parameter, log files are saved in the specified folder. If you do not specify this parameter, log files are saved in the root directory of the destination bucket.
bucket.logging = Aliyun::OSS::BucketLogging.new(
  enable: true, target_bucket: 'logging_bucket', target_prefix: 'my-log')

Consulter les configurations de journalisation d'un bucket

Utilisez le code suivant pour consulter la configuration du stockage des journaux.

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) region is used as an example for the endpoint. Specify a region as needed.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before running this code, set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Specify the bucket name, for example, examplebucket.
bucket = client.get_bucket('examplebucket')
log = bucket.logging
puts log.to_s

Désactiver le stockage des journaux

Le code suivant montre comment désactiver la journalisation pour un bucket :

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) region is used as an example for the endpoint. Specify a region as needed.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before running this code, set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Specify the bucket name, for example, examplebucket.
bucket = client.get_bucket('examplebucket')
bucket.logging = Aliyun::OSS::BucketLogging.new(enable: false)

Références

  • Pour plus d'informations sur l'opération API permettant d'activer la journalisation pour un bucket, consultez PutBucketLogging.

  • Pour plus d'informations sur l'opération API permettant de consulter les configurations de journalisation d'un bucket, consultez GetBucketLogging.

  • Pour plus d'informations sur l'opération API permettant de désactiver la journalisation pour un bucket, consultez DeleteBucketLogging.