class Logsly::Logging182::Appenders::IO
This class provides an Appender
that can write to any IO
stream configured for writing.
Attributes
Public Class Methods
new( name, io )
click to toggle source
new( name, io, :layout → layout )
Creates a new IO
Appender
using the given name that will use the io stream as the logging destination.
Calls superclass method
Logsly::Logging182::Appenders::Buffering::new
# File lib/logsly/logging182/appenders/io.rb, line 30 def initialize( name, io, opts = {} ) unless io.respond_to? :syswrite raise TypeError, "expecting an IO object but got '#{io.class.name}'" end @io = io @io.sync = true if io.respond_to? :sync= # syswrite complains if the IO stream is buffered @io.flush rescue nil # syswrite also complains if in unbuffered mode and buffer isn't empty @close_method = :close super(name, opts) configure_buffering(opts) end
Public Instance Methods
close( footer = true )
click to toggle source
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.
Calls superclass method
Logsly::Logging182::Appenders::Buffering#close
# File lib/logsly/logging182/appenders/io.rb, line 52 def close( *args ) return self if @io.nil? super io, @io = @io, nil unless [STDIN, STDERR, STDOUT].include?(io) io.send(@close_method) if @close_method and io.respond_to? @close_method end rescue IOError ensure return self end
Private Instance Methods
canonical_write( str )
click to toggle source
This method is called by the buffering code when messages need to be written to the logging destination.
# File lib/logsly/logging182/appenders/io.rb, line 71 def canonical_write( str ) return self if @io.nil? str = str.force_encoding(encoding) if encoding and str.encoding != encoding @io.syswrite str self rescue StandardError => err self.level = :off ::Logsly::Logging182.log_internal {"appender #{name.inspect} has been disabled"} ::Logsly::Logging182.log_internal(-2) {err} end