Class: Plywood::Logger

Inherits:
IOHandler show all
Defined in:
lib/plywood/logger.rb

Overview

An IOHandler that outputs all process output, line by line, prefixed with “name | ”.

It keeps stderr and stdout separated which may be convenient if you want to pipe the output to another program.

Instance Method Summary collapse

Methods inherited from IOHandler

#start, #stop

Constructor Details

#initialize(ios) ⇒ Logger



10
11
12
13
14
15
16
# File 'lib/plywood/logger.rb', line 10

def initialize(ios)
  super
  @name_padding = [6, ios.map(&:name).map(&:size).max].max
  @names = ios.map(&:name).uniq
  Color.enable($stderr)
  Color.enable($stdout)
end

Instance Method Details

#handle_exit_statuses!(statuses, commands) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/plywood/logger.rb', line 26

def handle_exit_statuses!(statuses, commands)
  statuses.each do |pid, status|
    next if status.success?
    command = commands.detect { |item| item.pid == pid }
    log($stderr, command.name, "`#{command}` failed with status #{status.to_i}")
  end
  self
end

#handle_io!Object



18
19
20
21
22
23
24
# File 'lib/plywood/logger.rb', line 18

def handle_io!
  loop do
    readers, _writers = IO.select(@ios)
    readers.each { |stream| copy_stream_to_io(stream) }
  end
  self
end