Class: EventLogger::Output::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/event_logger/output/io.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ IO

Returns a new instance of IO.



12
13
14
# File 'lib/event_logger/output/io.rb', line 12

def initialize(stream)
  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



10
11
12
# File 'lib/event_logger/output/io.rb', line 10

def stream
  @stream
end

Instance Method Details

#write(severity, details = {}) ⇒ Object



16
17
18
19
20
# File 'lib/event_logger/output/io.rb', line 16

def write(severity, details = {})
  timestamp = (Time.now.to_f * 1000).to_i
  line = JSON.generate({ generated_at: timestamp, severity: severity }.merge(details))
  @stream << "#{line}\n"
end