Class: Intake::IOSink

Inherits:
Sink
  • Object
show all
Defined in:
lib/intake/io_sink.rb

Overview

Sink that writes log events to IO stream, e.g., STDOUT or file stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Sink

#add_filter, #flush, #receive

Constructor Details

#initialize(io) ⇒ IOSink

Returns a new instance of IOSink.



10
11
12
13
14
15
# File 'lib/intake/io_sink.rb', line 10

def initialize(io)
  super()
  @io = io
  @formatter = ::Intake::Formatter.new
  @exception_formatter = ::Intake::ExceptionFormatter.new
end

Instance Attribute Details

#exception_formatterObject

Returns the value of attribute exception_formatter.



17
18
19
# File 'lib/intake/io_sink.rb', line 17

def exception_formatter
  @exception_formatter
end

#formatterObject

Returns the value of attribute formatter.



17
18
19
# File 'lib/intake/io_sink.rb', line 17

def formatter
  @formatter
end

Instance Method Details

#drain(event) ⇒ Object



19
20
21
22
23
# File 'lib/intake/io_sink.rb', line 19

def drain(event)
  error_message = "\n#{@exception_formatter.call(event[:error])}" unless event[:error].nil?
  txt = "#{@formatter.call(event)}#{error_message}\n"
  @io.write(txt)
end