Class: Logsly::Logging182::Appenders::IO
- Inherits:
-
Logsly::Logging182::Appender
- Object
- Logsly::Logging182::Appender
- Logsly::Logging182::Appenders::IO
- Includes:
- Buffering
- Defined in:
- lib/logsly/logging182/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 collapse
-
#close_method ⇒ Object
The method that will be used to close the IO stream.
Attributes included from Buffering
#auto_flushing, #buffer, #flush_period
Attributes inherited from Logsly::Logging182::Appender
Instance Method Summary collapse
-
#close(*args) ⇒ Object
call-seq: close( footer = true ).
-
#initialize(name, io, opts = {}) ⇒ IO
constructor
call-seq: IO.new( name, io ) IO.new( name, io, :layout => layout ).
Methods included from Buffering
#flush, #immediate_at=, #reopen
Methods inherited from Logsly::Logging182::Appender
#<<, #append, #closed?, #encoding, #encoding=, #flush, #inspect, #reopen
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#close_method ⇒ Object
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.
21 22 23 |
# File 'lib/logsly/logging182/appenders/io.rb', line 21 def close_method @close_method 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.
52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |