El registro de accesos de Object Storage Service (OSS) captura información detallada sobre las solicitudes que se envían a sus buckets. Una vez que habilite el registro en un bucket de origen, OSS generará y entregará automáticamente los archivos de registro cada hora al bucket de destino que especifique, mediante una convención de nombres predefinida.
Habilitar el registro de un bucket
Utilice a continuación código para habilitar la función de almacenamiento de registros.
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')
Consultar la configuración de registro de un bucket
Utilice a continuación código para consultar la configuración del almacenamiento de registros.
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
Deshabilitar el almacenamiento de registros
A continuación se muestra un ejemplo de cómo deshabilitar el registro de 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)
Referencias
Para obtener más información sobre la API que permite habilitar el registro de un bucket, consulte PutBucketLogging.
Si necesita detalles sobre la API para consultar la configuración de registro de un bucket, consulte GetBucketLogging.
En cuanto a la API que sirve para deshabilitar el registro de un bucket, consulte DeleteBucketLogging.