Class: AWS::S3::Logging::Log::Line
- Inherits:
-
String
- Object
- String
- AWS::S3::Logging::Log::Line
- Defined in:
- lib/aws/s3/logging.rb
Overview
Each line of a log exposes the raw line, but it also has method accessors for all the fields of the logged request.
The list of supported log line fields are listed in the S3 documentation: docs.amazonwebservices.com/AmazonS3/2006-03-01/LogFormat.html
line = log.lines.first
line.remote_ip
# => '72.21.206.5'
If a certain field does not apply to a given request (for example, the key
field does not apply to a bucket request), or if it was unknown or unavailable, it will return nil
.
line.operation
# => 'REST.GET.BUCKET'
line.key
# => nil
Constant Summary collapse
- DATE =
/\[([^\]]+)\]/
- QUOTED_STRING =
/"([^"]+)"/
- REST =
/(\S+)/
- LINE_SCANNER =
/#{DATE}|#{QUOTED_STRING}|#{REST}/
- @@decorators =
Hash.new {|hash, key| hash[key] = lambda {|entry| CoercibleString.coerce(entry)}}
- @@fields =
[]
Class Method Summary collapse
-
.field(name, offset, type = nil, &block) ⇒ Object
:nodoc:.
-
.typecast_time(datetime) ⇒ Object
Time.parse doesn’t like %d/%B/%Y:%H:%M:%S %z so we have to transform it unfortunately.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns all fields of the line in a hash of the form
:field_name => :field_value
. -
#initialize(line) ⇒ Line
constructor
:nodoc:.
Constructor Details
#initialize(line) ⇒ Line
:nodoc:
165 166 167 168 |
# File 'lib/aws/s3/logging.rb', line 165 def initialize(line) #:nodoc: super(line) @parts = parse end |
Class Method Details
.field(name, offset, type = nil, &block) ⇒ Object
:nodoc:
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/aws/s3/logging.rb', line 139 def field(name, offset, type = nil, &block) #:nodoc: decorators[name] = block if block_given? fields << name class_eval(<<-EVAL, __FILE__, __LINE__) def #{name} value = parts[#{offset} - 1] if value == '-' nil else self.class.decorators[:#{name}].call(value) end end memoized :#{name} EVAL end |
.typecast_time(datetime) ⇒ Object
Time.parse doesn’t like %d/%B/%Y:%H:%M:%S %z so we have to transform it unfortunately
156 157 158 159 160 161 162 |
# File 'lib/aws/s3/logging.rb', line 156 def typecast_time(datetime) #:nodoc: month = datetime[/[a-z]+/i] datetime.sub!(%r|^(\w{2})/(\w{3})|, '\2/\1') datetime.sub!(month, Date::ABBR_MONTHS[month.downcase].to_s) datetime.sub!(':', ' ') Time.parse(datetime) end |
Instance Method Details
#attributes ⇒ Object
Returns all fields of the line in a hash of the form :field_name => :field_value
.
line.attributes.values_at(:bucket, :key)
# => ['marcel', 'kiss.jpg']
192 193 194 195 196 197 |
# File 'lib/aws/s3/logging.rb', line 192 def attributes self.class.fields.inject({}) do |attribute_hash, field| attribute_hash[field] = send(field) attribute_hash end end |