Class: Synco::LogPipe

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LogPipe.



158
159
160
161
162
163
164
165
166
167
# File 'lib/synco/scope.rb', line 158

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

Instance Method Details

#closeObject



169
170
171
172
173
174
175
176
177
178
# File 'lib/synco/scope.rb', line 169

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