This class provides an Appender that can write to a StringIO instance. This is very useful for testing log message output.
The StringIO instance the appender is writing to.
Creates a new StringIo appender that will append log messages to a StringIO instance.
# File lib/logging/appenders/string_io.rb, line 18 def initialize( name, opts = {} ) @sio = StringIO.new @sio.extend IoToS @pos = 0 super(name, @sio, opts) end
Clears the internal StringIO instance. All log messages are removed from the buffer.
# File lib/logging/appenders/string_io.rb, line 46 def clear @mutex.synchronize { @pos = 0 @sio.seek 0 @sio.truncate 0 } end
Reopen the underlying StringIO instance. If the instance is currently closed then it will be opened. If the instance is currently open then it will be closed and immediately opened.
# File lib/logging/appenders/string_io.rb, line 29 def reopen @mutex.synchronize { if defined? @io and @io flush @io.close rescue nil end @io = @sio = StringIO.new @sio.extend IoToS @pos = 0 } super self end