Class: Logging::Appenders::IO

Inherits:
Logging::Appender show all
Defined in:
lib/gems/logging-0.9.4/lib/logging/appenders/io.rb

Overview

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

Direct Known Subclasses

File, RollingFile, Stderr, Stdout

Instance Attribute Summary

Attributes inherited from Logging::Appender

#layout, #level, #name

Instance Method Summary collapse

Methods inherited from Logging::Appender

#<<, [], []=, #append, #closed?, #inspect, 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.



16
17
18
19
20
21
22
23
24
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/io.rb', line 16

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 if @io.respond_to?('sync') rescue nil
  super(name, opts)
end

Instance Method Details

#close(*args) ⇒ Object

call-seq:

close( footer = 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.



34
35
36
37
38
39
40
41
42
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/io.rb', line 34

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

#flushObject

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.



50
51
52
53
54
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/io.rb', line 50

def flush
  return self if @io.nil?
  @io.flush
  self
end