Class: ObservationCompiler::LogLine

Inherits:
Object
  • Object
show all
Defined in:
lib/logbox/observation_compiler.rb

Constant Summary collapse

TIMESTAMP_MATCHER =
/(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)\s([-+]?\d{2})/

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ LogLine

Returns a new instance of LogLine.



234
235
236
# File 'lib/logbox/observation_compiler.rb', line 234

def initialize(line)
  @line = Logbox::StringEncoder.iconv(line)
end

Instance Method Details

#dateObject



263
264
265
# File 'lib/logbox/observation_compiler.rb', line 263

def date
  timestamp.send :to_date
end

#normalizeObject



245
246
247
248
249
250
# File 'lib/logbox/observation_compiler.rb', line 245

def normalize
  normalize_s3_format
  normalize_apache_format
  normalize_timestamp
  @line
end

#timestampObject



254
255
256
257
258
259
260
261
# File 'lib/logbox/observation_compiler.rb', line 254

def timestamp
  unless @timestamp
    match = @line.match(TIMESTAMP_MATCHER)
    @timestamp = Time.utc(match[3], match[2], match[1], match[4], match[5], match[6])
    @timestamp -= match[7].to_i * 3600  # Correct the zone. Works only on whole hours timezones.
  end
  @timestamp
end

#to_sObject



267
268
269
# File 'lib/logbox/observation_compiler.rb', line 267

def to_s
  @line
end

#valid?Boolean

Returns:

  • (Boolean)


238
239
240
241
242
243
# File 'lib/logbox/observation_compiler.rb', line 238

def valid?
  normalize
  true
rescue
  false
end