Parent

Included Modules

Logging::Appenders::IO

This class provides an Appender that can write to any IO stream configured for writing.

Attributes

close_method[RW]

The method that will be used to close the IO stream. Defaults to :close but can be :close_read, :close_write or nil. When nil, the IO stream will not be closed when the appender’s close method is called.

Public Class Methods

new( name, io, :layout => layout ) click to toggle source

Creates a new IO Appender using the given name that will use the io stream as the logging destination.

    # File lib/logging/appenders/io.rb, line 30
30:     def initialize( name, io, opts = {} )
31:       unless io.respond_to? :syswrite
32:         raise TypeError, "expecting an IO object but got '#{io.class.name}'"
33:       end
34: 
35:       @io = io
36:       @io.sync = true if io.respond_to? :sync=    # syswrite complains if the IO stream is buffered
37:       @io.flush rescue nil                        # syswrite also complains if in unbuffered mode and buffer isn't empty
38:       @close_method = :close
39: 
40:       super(name, opts)
41:       configure_buffering(opts)
42:     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.

    # File lib/logging/appenders/io.rb, line 52
52:     def close( *args )
53:       return self if @io.nil?
54:       super
55: 
56:       io, @io = @io, nil
57:       unless [STDIN, STDERR, STDOUT].include?(io)
58:         io.send(@close_method) if @close_method and io.respond_to? @close_method
59:       end
60:     rescue IOError
61:     ensure
62:       return self
63:     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/logging/appenders/io.rb, line 71
71:     def canonical_write( str )
72:       return self if @io.nil?
73:       @io.syswrite str
74:       self
75:     rescue StandardError => err
76:       self.level = :off
77:       ::Logging.log_internal {"appender #{name.inspect} has been disabled"}
78:       ::Logging.log_internal(2) {err}
79:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.