Class: LogBench::Log::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/log_bench/log/entry.rb

Direct Known Subclasses

CacheEntry, CallLineEntry, QueryEntry, Request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_line) ⇒ Entry

Returns a new instance of Entry.



8
9
10
11
12
13
# File 'lib/log_bench/log/entry.rb', line 8

def initialize(raw_line)
  self.raw_line = raw_line.strip
  self.timestamp = Time.now
  self.type = :unknown
  parse!
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def content
  @content
end

#raw_lineObject

Returns the value of attribute raw_line.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def raw_line
  @raw_line
end

#request_idObject

Returns the value of attribute request_id.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def request_id
  @request_id
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def timestamp
  @timestamp
end

#timingObject

Returns the value of attribute timing.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def timing
  @timing
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/log_bench/log/entry.rb', line 6

def type
  @type
end

Class Method Details

.build(raw_line) ⇒ Object



15
16
17
# File 'lib/log_bench/log/entry.rb', line 15

def self.build(raw_line)
  new(raw_line) if parseable?(raw_line)
end

.parseable?(line) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/log_bench/log/entry.rb', line 19

def self.parseable?(line)
  data = JSON.parse(line.strip)
  data.is_a?(Hash)
rescue JSON::ParserError
  false
end

Instance Method Details

#http_request?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/log_bench/log/entry.rb', line 26

def http_request?
  type == :http_request
end

Returns:

  • (Boolean)


30
31
32
# File 'lib/log_bench/log/entry.rb', line 30

def related_log?
  !http_request?
end

#to_hObject



34
35
36
37
38
39
40
41
# File 'lib/log_bench/log/entry.rb', line 34

def to_h
  {
    raw: raw_line,
    timestamp: timestamp,
    request_id: request_id,
    type: type
  }
end