Class: Logging::Appenders::IO
- Inherits:
-
Logging::Appender
- Object
- Logging::Appender
- Logging::Appenders::IO
- Includes:
- Buffering
- 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
Constant Summary
Constants included from Buffering
Buffering::DEFAULT_BUFFER_SIZE
Instance Attribute Summary
Attributes included from Buffering
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 included from Buffering
Methods inherited from Logging::Appender
#<<, #append, #closed?, #inspect, #reopen
Constructor Details
#initialize(name, io, opts = {}) ⇒ IO
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/logging/appenders/io.rb', line 17 def initialize( name, io, opts = {} ) unless io.respond_to? :write raise TypeError, "expecting an IO object but got '#{io.class.name}'" end @io = io @io.sync = true if @io.respond_to?(:sync) rescue nil configure_buffering(opts) 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.
37 38 39 40 41 42 43 44 45 |
# File 'lib/logging/appenders/io.rb', line 37 def close( *args ) return self if @io.nil? super 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.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/logging/appenders/io.rb', line 53 def flush return self if @io.nil? @io.write(buffer.join) unless buffer.empty? @io.flush self rescue StandardError => err self.level = :off ::Logging.log_internal {"appender #{name.inspect} has been disabled"} ::Logging.log_internal(-2) {err} ensure buffer.clear end |