Class: Arrow::Logger::Outputter

Inherits:
Object
  • Object
show all
Includes:
PluginFactory
Defined in:
lib/arrow/logger/outputter.rb

Overview

The Arrow::Logger::Outputter class, which is the abstract base class for objects that control where logging output is sent in an Arrow::Logger object.

Authors

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

Direct Known Subclasses

ApacheOutputter, ArrayOutputter, FileOutputter

Constant Summary collapse

DEFAULT_DESCRIPTION =

The default description

"Logging Outputter"
DEFAULT_FORMAT =

The default interpolatable string that’s used to build the message to output

%q{#{time.strftime('%Y/%m/%d %H:%M:%S')} [#{level}]: #{name} } +
%q{#{frame ? '('+frame+')' : ''}: #{msg[0,1024]}}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new Arrow::Logger::Outputter object with the given uri, description and sprintf-style format.



65
66
67
68
# File 'lib/arrow/logger/outputter.rb', line 65

def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT )
	@description = description
	@format = format
end

Instance Attribute Details

#descriptionObject

The outputter’s description, for introspection utilities.



76
77
78
# File 'lib/arrow/logger/outputter.rb', line 76

def description
  @description
end

#formatObject

The uninterpolated string format for this outputter. This message written will be formed by interpolating this string in the #write method’s context immediately before outputting.



81
82
83
# File 'lib/arrow/logger/outputter.rb', line 81

def format
  @format
end

Class Method Details

.create(uri, *args) ⇒ Object

Create a new Arrow::Logger::Outputter object of the type specified by uri.



52
53
54
55
# File 'lib/arrow/logger/outputter.rb', line 52

def self::create( uri, *args )
	uri = self.parse_uri( uri ) if uri.is_a?( String )
	super( uri.scheme.dup, uri, *args )
end

.derivativeDirsObject

Specify the directory to look for the derivatives of this class in.



36
37
38
# File 'lib/arrow/logger/outputter.rb', line 36

def self::derivativeDirs
	["arrow/logger"]
end

.parse_uri(str) ⇒ Object

Parse the given string into a URI object, appending the path part if it doesn’t exist.



43
44
45
46
47
# File 'lib/arrow/logger/outputter.rb', line 43

def self::parse_uri( str )
	return str if str.is_a?( URI::Generic )
	str += ":." if str.match( /^\w+$/ )
	URI.parse( str )
end

Instance Method Details

#inspectObject

Returns a human-readable description of the object as a String



101
102
103
104
105
106
107
# File 'lib/arrow/logger/outputter.rb', line 101

def inspect
	"#<%s:0x%0x %s>" % [
		self.class.name,
		self.object_id * 2,
		self.inspection_details,
	]
end

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

Write the given level, name, frame, and msg to the target output mechanism. Subclasses can call this with a block which will be passed the formatted message. If no block is supplied by the child, this method will check to see if $DEBUG is set, and if it is, write the log message to $stderr.



89
90
91
92
93
94
95
96
97
# File 'lib/arrow/logger/outputter.rb', line 89

def write( time, level, name, frame, msg )
	msg = @format.interpolate( binding )

	if block_given?
		yield( msg )
	else
		$stderr.puts( msg ) if $DEBUG
	end
end