Class: Logn::Event

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

Constant Summary collapse

LOG_LINE_REGEX =
/^
(?<level>\w)
,\s
\[
  (?<timestamp>\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d+)
  \s
  \#(?<pid>\d+)
\]
\s+
(?<severity>\w+)
\s--\s:\s
(?<sender>[\w.]+)
(?<event>:\w+)?
\s
(?<json>.*)
$/x

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Event

Returns a new instance of Event.



100
101
102
# File 'lib/logn.rb', line 100

def initialize(line)
  @line = line
end

Instance Method Details

#eventObject



124
125
126
# File 'lib/logn.rb', line 124

def event
  @event ||= (match[:event] and match[:event].gsub(/^:/, '').downcase.to_sym)
end

#levelObject



104
105
106
# File 'lib/logn.rb', line 104

def level
  match[:level]
end

#metadataObject



128
129
130
131
# File 'lib/logn.rb', line 128

def 
  return nil unless match[:json]
   ||= JSON.parse(match[:json])
end

#pidObject



112
113
114
# File 'lib/logn.rb', line 112

def pid
  match[:pid]
end

#senderObject



120
121
122
# File 'lib/logn.rb', line 120

def sender
  match[:sender]
end

#severityObject



116
117
118
# File 'lib/logn.rb', line 116

def severity
  @severity ||= match[:severity].downcase.to_sym
end

#timestampObject



108
109
110
# File 'lib/logn.rb', line 108

def timestamp
  @timestamp ||= Time.iso8601(match[:timestamp])
end