Class: Logging::Appenders::StringIo
- Inherits:
-
IO
- Object
- Logging::Appender
- IO
- Logging::Appenders::StringIo
- Defined in:
- lib/logging/appenders/string_io.rb
Overview
This class provides an Appender that can write to a StringIO instance. This is very useful for testing log message output.
Defined Under Namespace
Modules: IoToS
Constant Summary
Constants included from Buffering
Buffering::DEFAULT_BUFFER_SIZE
Instance Attribute Summary collapse
-
#sio ⇒ Object
readonly
The StringIO instance the appender is writing to.
Attributes included from Buffering
Attributes inherited from Logging::Appender
Instance Method Summary collapse
-
#clear ⇒ Object
(also: #reset)
Clears the internal StringIO instance.
-
#initialize(name, opts = {}) ⇒ StringIo
constructor
call-seq: StringIo.new( name, opts = {} ).
Methods inherited from IO
Methods included from Buffering
Methods inherited from Logging::Appender
#<<, #append, #close, #closed?, #flush, #inspect, #reopen
Constructor Details
#initialize(name, opts = {}) ⇒ StringIo
call-seq:
StringIo.new( name, opts = {} )
Creates a new StrinIo appender that will append log messages to a StringIO instance.
18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#sio ⇒ Object (readonly)
The StringIO instance the appender is writing to.
10 11 12 |
# File 'lib/logging/appenders/string_io.rb', line 10 def sio @sio end |
Instance Method Details
#clear ⇒ Object Also known as: reset
Clears the internal StringIO instance. All log messages are removed from the buffer.
28 29 30 31 32 33 34 |
# File 'lib/logging/appenders/string_io.rb', line 28 def clear sync { @pos = 0 @sio.seek 0 @sio.truncate 0 } end |