Class: CFTools::Tunnel::LogEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/tools-cf-plugin/tunnel/log_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, line, stream) ⇒ LogEntry

Returns a new instance of LogEntry.



9
10
11
12
13
14
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 9

def initialize(label, line, stream)
  @label = label
  @line = line
  @stream = stream
  @fallback_timestamp = Time.now
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 7

def label
  @label
end

#lineObject (readonly)

Returns the value of attribute line.



7
8
9
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 7

def line
  @line
end

#streamObject (readonly)

Returns the value of attribute stream.



7
8
9
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 7

def stream
  @stream
end

Instance Method Details

#dataObject



29
30
31
32
33
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 29

def data
  json = JSON.parse(@line)
  json["data"]
rescue JSON::ParserError
end

#log_levelObject



23
24
25
26
27
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 23

def log_level
  json = JSON.parse(@line)
  json["log_level"]
rescue JSON::ParserError
end

#messageObject



16
17
18
19
20
21
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 16

def message
  json = JSON.parse(@line)
  json["message"]
rescue JSON::ParserError
  @line
end

#timestampObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tools-cf-plugin/tunnel/log_entry.rb', line 35

def timestamp
  json = JSON.parse(@line)

  timestamp = json["timestamp"]
  case timestamp
  when String
    Time.parse(timestamp)
  when Numeric
    Time.at(timestamp)
  else
    @fallback_timestamp
  end
rescue JSON::ParserError
  @fallback_timestamp
end