Class: Arrow::Logger::FileOutputter
- Inherits:
-
Outputter
- Object
- Outputter
- Arrow::Logger::FileOutputter
- 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
Michael Granger
Please see the file LICENSE in the top-level directory for licensing details.
Direct Known Subclasses
Constant Summary
- DEFAULT_DESCRIPTION =
The default description
"File Outputter"
- DEFAULT_FORMAT =
The default format (copied from the superclass)
Arrow::Logger::Outputter::DEFAULT_FORMAT
Constants inherited from Outputter
DEFAULT_DESCRIPTION, DEFAULT_FORMAT
Instance Attribute Summary
-
- (Object) io
The filehandle open to the logfile.
Instance Method Summary
-
- (FileOutputter) initialize(uri, description = DEFAULT_DESCRIPTION, format = DEFAULT_FORMAT)
constructor
Create a new Arrow::Logger::FileOutputter object.
-
- (Object) inspection_details
protected
Returns a String which should be included in the implementation-specific part of the object’s inspection String.
-
- (Object) write(time, level, name, frame, msg)
Write the given level, name, frame, and msg to the logfile.
Methods inherited from Outputter
create, derivativeDirs, #inspect, parse_uri
Constructor Details
- (FileOutputter) initialize(uri, description = DEFAULT_DESCRIPTION, format = DEFAULT_FORMAT)
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
- (Object) io
The filehandle open to the logfile
61 62 63 |
# File 'lib/arrow/logger/fileoutputter.rb', line 61 def io @io end |
Instance Method Details
- (Object) inspection_details (protected)
Returns a String which should be included in the implementation-specific part of the object’s inspection String.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/arrow/logger/fileoutputter.rb', line 80 def inspection_details io_desc = case @io when $stderr 'STDERR' when $stdout 'STDOUT' when StringIO '(StringIO 0x%0x)' % [ @io.object_id * 2 ] else '(IO: fd %d)' % [ @io.fileno ] end return [ super, io_desc ].join(', ') end |
- (Object) write(time, level, name, frame, msg)
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 |