Class: SimplyGenius::Atmos::Logging::CaptureStream
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SimplyGenius::Atmos::Logging::CaptureStream
- Defined in:
- lib/simplygenius/atmos/logging.rb
Instance Method Summary collapse
-
#initialize(logger_name, appender, stream, color = nil) ⇒ CaptureStream
constructor
A new instance of CaptureStream.
- #strip_color(str) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(logger_name, appender, stream, color = nil) ⇒ CaptureStream
Returns a new instance of CaptureStream.
28 29 30 31 32 33 34 |
# File 'lib/simplygenius/atmos/logging.rb', line 28 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
36 37 38 |
# File 'lib/simplygenius/atmos/logging.rb', line 36 def strip_color(str) str.gsub(/\e\[\d+m/, '') end |
#write(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simplygenius/atmos/logging.rb', line 40 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 |