Class: Logging::Appenders::IO
- Inherits:
-
Logging::Appender
- Object
- Logging::Appender
- Logging::Appenders::IO
- Defined in:
- lib/logging/appenders/io.rb
Overview
This class provides an Appender that can write to any IO stream configured for writing.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Logging::Appender
Instance Method Summary collapse
-
#close(*args) ⇒ Object
call-seq: close( footer = true ).
-
#flush ⇒ Object
call-seq: flush.
-
#initialize(name, io, opts = {}) ⇒ IO
constructor
call-seq: IO.new( name, io ) IO.new( name, io, :layout => layout ).
Methods inherited from Logging::Appender
#<<, [], []=, #append, #closed?, remove, stderr, stdout
Constructor Details
#initialize(name, io, opts = {}) ⇒ IO
call-seq:
IO.new( name, io )
IO.new( name, io, :layout => layout )
Creates a new IO Appender using the given name that will use the io stream as the logging destination.
17 18 19 20 21 22 23 24 25 |
# File 'lib/logging/appenders/io.rb', line 17 def initialize( name, io, opts = {} ) unless io.respond_to? :print raise TypeError, "expecting an IO object but got '#{io.class.name}'" end @io = io @io.sync = true super(name, opts) end |
Instance Method Details
#close(*args) ⇒ Object
call-seq:
close( = true )
Close the appender and writes the layout footer to the logging destination if the footer flag is set to true
. Log events will no longer be written to the logging destination after the appender is closed.
35 36 37 38 39 40 41 42 43 |
# File 'lib/logging/appenders/io.rb', line 35 def close( *args ) return self if @io.nil? super(*args) io, @io = @io, nil io.close unless [STDIN, STDERR, STDOUT].include?(io) rescue IOError => err ensure return self end |
#flush ⇒ Object
call-seq:
flush
Call flush
to force an appender to write out any buffered log events. Similar to IO#flush, so use in a similar fashion.
51 52 53 54 55 |
# File 'lib/logging/appenders/io.rb', line 51 def flush return self if @io.nil? @io.flush self end |