class Logging::Appenders::StringIo

This class provides an Appender that can write to a StringIO instance. This is very useful for testing log message output.

Attributes

sio[R]

The StringIO instance the appender is writing to.

Public Class Methods

new( name, opts = {} ) click to toggle source

Creates a new StringIo appender that will append log messages to a StringIO instance.

Calls superclass method Logging::Appenders::IO.new
# File lib/logging/appenders/string_io.rb, line 25
def initialize( name, opts = {} )
  @sio = StringIO.new
  @sio.extend IoToS
  @pos = 0
  super(name, @sio, opts)
end

Public Instance Methods

clear() click to toggle source

Clears the internal StringIO instance. All log messages are removed from the buffer.

# File lib/logging/appenders/string_io.rb, line 53
def clear
  @mutex.synchronize {
    @pos = 0
    @sio.seek 0
    @sio.truncate 0
  }
end
Also aliased as: reset
reopen() click to toggle source

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.

Calls superclass method Logging::Appenders::Buffering#reopen
# File lib/logging/appenders/string_io.rb, line 36
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
reset()
Alias for: clear