Class: LogSinks::IOSink

Inherits:
Sink
  • Object
show all
Defined in:
lib/log_sinks/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, pump_class: LogSinks::Pumps::InThreadPump) ⇒ IOSink

Returns a new instance of IOSink.



9
10
11
12
13
# File 'lib/log_sinks/io_sink.rb', line 9

def initialize(io, pump_class: LogSinks::Pumps::InThreadPump)
  super(pump_class: pump_class)
  @io = io
  @formatter = ::LogSinks::Formatter.new
end

Instance Attribute Details

#formatter=(value) ⇒ Object (writeonly)

Sets the attribute formatter

Parameters:

  • value

    the value to set the attribute formatter to.



15
16
17
# File 'lib/log_sinks/io_sink.rb', line 15

def formatter=(value)
  @formatter = value
end

Instance Method Details

#drain(event) ⇒ Object



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

def drain(event)
  txt = @formatter.call(event)
  @io.write(txt)
end