Class: Arrow::Logger::FileOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/arrow/logger/fileoutputter.rb

Overview

The Arrow::Logger::FileOutputter class, a derivative of Apache::Logger::Outputter. This is an outputter that writes to a file or other filehandle.

Authors

Please see the file LICENSE in the top-level directory for licensing details.

Direct Known Subclasses

ColorOutputter, HtmlOutputter

Constant Summary collapse

DEFAULT_DESCRIPTION =

The default description

"File Outputter"
DEFAULT_FORMAT =

The default format (copied from the superclass)

Arrow::Logger::Outputter::DEFAULT_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Outputter

#description, #format

Instance Method Summary collapse

Methods inherited from Outputter

create, derivativeDirs, #inspect, parse_uri

Constructor Details

#initialize(uri, description = DEFAULT_DESCRIPTION, format = DEFAULT_FORMAT) ⇒ FileOutputter

Create a new Arrow::Logger::FileOutputter object. The io argument can be an IO or StringIO object, in which case output is sent to it directly, a String, in which case it is used as the first argument to File.open, or an Integer file descriptor, in which case a new IO object is created which appends to the file handle matching that descriptor.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/arrow/logger/fileoutputter.rb', line 36

def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT )
  if uri.hierarchical?
    @io = File.open( uri.path, File::WRONLY|File::CREAT )
  else
    case uri.opaque
    when /(std|def)err/i
      @io = $stderr
    when /(std|def)out/i
      @io = $defout
    when /^(\d+)$/
      @io = IO.for_fd( Integer($1), "w" )
    else
      raise "Unrecognized log URI '#{uri}'"
    end
  end

  super
end

Instance Attribute Details

#ioObject

The filehandle open to the logfile



61
62
63
# File 'lib/arrow/logger/fileoutputter.rb', line 61

def io
  @io
end

Instance Method Details

#write(time, level, name, frame, msg) ⇒ Object

Write the given level, name, frame, and msg to the logfile.



65
66
67
68
69
70
71
# File 'lib/arrow/logger/fileoutputter.rb', line 65

def write( time, level, name, frame, msg )
  if block_given?
    super
  else
    super {|msg| @io.puts(msg) }
  end
end