Class: Synco::LogPipe
- Inherits:
-
IO
- Object
- IO
- Synco::LogPipe
- Defined in:
- lib/synco/scope.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(logger, level = :info) ⇒ LogPipe
constructor
A new instance of LogPipe.
Constructor Details
#initialize(logger, level = :info) ⇒ LogPipe
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/synco/scope.rb', line 149 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
#close ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/synco/scope.rb', line 160 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 |