Module AWS::S3::Logging
In: lib/aws/s3/logging.rb

A bucket can be set to log the requests made on it. By default logging is turned off. You can check if a bucket has logging enabled:

  Bucket.logging_enabled_for? 'jukebox'
  # => false

Enabling it is easy:

  Bucket.enable_logging_for('jukebox')

Unless you specify otherwise, logs will be written to the bucket you want to log. The logs are just like any other object. By default they will start with the prefix ‘log-’. You can customize what bucket you want the logs to be delivered to, as well as customize what the log objects’ key is prefixed with by setting the target_bucket and target_prefix option:

  Bucket.enable_logging_for(
    'jukebox', 'target_bucket' => 'jukebox-logs'
  )

Now instead of logging right into the jukebox bucket, the logs will go into the bucket called jukebox-logs.

Once logs have accumulated, you can access them using the logs method:

  pp Bucket.logs('jukebox')
  [#<AWS::S3::Logging::Log '/jukebox-logs/log-2006-11-14-07-15-24-2061C35880A310A1'>,
   #<AWS::S3::Logging::Log '/jukebox-logs/log-2006-11-14-08-15-27-D8EEF536EC09E6B3'>,
   #<AWS::S3::Logging::Log '/jukebox-logs/log-2006-11-14-08-15-29-355812B2B15BD789'>]

Each log has a lines method that gives you information about each request in that log. All the fields are available as named methods. More information is available in Logging::Log::Line.

  logs = Bucket.logs('jukebox')
  log  = logs.first
  line = log.lines.first
  line.operation
  # => 'REST.GET.LOGGING_STATUS'
  line.request_uri
  # => 'GET /jukebox?logging HTTP/1.1'
  line.remote_ip
  # => "67.165.183.125"

Disabling logging is just as simple as enabling it:

 Bucket.disable_logging_for('jukebox')

Classes and Modules

Class AWS::S3::Logging::Log
Class AWS::S3::Logging::Status

[Validate]