lib/multi_process/logger.rb in multi_process-0.4.0 vs lib/multi_process/logger.rb in multi_process-0.5.0
- old
+ new
@@ -1,22 +1,20 @@
module MultiProcess
-
# Can create pipes and multiplex pipe content to put into
# given IO objects e.g. multiple output from multiple
# processes to current stdout.
#
class Logger < Receiver
-
# Create new logger.
#
# @param out [IO] IO to push formatted output from
# default created logger pipes.
# @param err [IO] IO to push formatted output from
# error sources.
#
def initialize(*args)
- @opts = Hash === args.last ? args.pop : Hash.new
+ @opts = Hash === args.last ? args.pop : {}
@out = args[0] || $stdout
@err = args[1] || $stderr
super()
end
@@ -41,18 +39,19 @@
def collapse?
@opts[:collapse].nil? || @opts[:collapse]
end
private
+
def output(process, line, opts = {})
@mutex.synchronize do
opts[:delimiter] ||= ' |'
name = if opts[:name]
- opts[:name].to_s.dup
- else
- max = @readers.values.map{|h| h[:process] ? h[:process].title.length : 0 }.max
- process ? process.title.to_s.rjust(max, ' ') : (' ' * max)
+ opts[:name].to_s.dup
+ else
+ max = @readers.values.map { |h| h[:process] ? h[:process].title.length : 0 }.max
+ process ? process.title.to_s.rjust(max, ' ') : (' ' * max)
end
io = opts[:io] || @out
if @last_name == name && collapse?
io.print " #{' ' * name.length} #{opts[:delimiter]} "
@@ -66,10 +65,10 @@
end
end
class << self
def global
- @global ||= self.new $stdout, $stderr
+ @global ||= new $stdout, $stderr
end
end
end
end