Class: Synco::LogPipe

Inherits:
IO
  • Object
show all
Defined in:
lib/synco/scope.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger: Console, level: :info) ⇒ LogPipe

Returns a new instance of LogPipe.



127
128
129
130
131
132
133
134
135
# File 'lib/synco/scope.rb', line 127

def initialize(logger: Console, level: :info)
  @input, @output = IO.pipe
  
  super(@output)
  
  @thread = Thread.new do
    @input.each{|line| logger.send(level, line.chomp!)}
  end
end

Instance Method Details

#closeObject



137
138
139
140
141
142
143
144
145
146
# File 'lib/synco/scope.rb', line 137

def close
  # Close the output pipe, we should never be writing to this anyway:
  @output.close
  
  # Wait for the thread to read everything and join:
  @thread.join
  
  # Close the input pipe because it's already closed on the remote end:
  @input.close
end