Class: SimplyGenius::Atmos::Logging::CaptureStream

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/simplygenius/atmos/logging.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger_name, appender, stream, color = nil) ⇒ CaptureStream

Returns a new instance of CaptureStream.



27
28
29
30
31
32
33
# File 'lib/simplygenius/atmos/logging.rb', line 27

def initialize(logger_name, appender, stream, color=nil)
  super(stream)
  @color = stream.tty? && color ? color : nil
  @logger = ::Logging.logger[logger_name]
  @logger.appenders = [appender]
  @logger.additive = false
end

Instance Method Details

#strip_color(str) ⇒ Object



35
36
37
# File 'lib/simplygenius/atmos/logging.rb', line 35

def strip_color(str)
  str.gsub(/\e\[\d+m/, '')
end

#write(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simplygenius/atmos/logging.rb', line 39

def write(data)
  @logger.info(strip_color(data))
  if @color
    count = 0
    d = data.lines.each do |l|
      cl = Kernel.send(:Rainbow, l).send(@color)
      count += super(cl)
    end
    return count
  else
    return super(data)
  end
end