Sha256: de73e75b684b7294269683d030419de3611c566410d03c32578642f8cbd1ae1a

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# -*- ruby -*-
#encoding: utf-8

require 'loggability' unless defined?( Loggability )

# Methods to install for objects which call +log_to+.
module Loggability::LogClient

	##
	# The key of the log host this client targets
	attr_accessor :log_host_key

	### Return the Loggability::Logger object associated with the log host the
	### client is logging to.
	### :TODO: Use delegation for efficiency.
	def log
		@__log ||= Loggability[ self ].proxy_for( self )
	end


	### Inheritance hook -- set the log host key of subclasses to the same
	### thing as the extended class.
	def inherited( subclass )
		super
		Loggability.log.debug "Setting up subclass %p of %p to log to %p" %
			[ subclass, self, self.log_host_key ]
		subclass.log_host_key = self.log_host_key
	end


	# Stuff that gets added to instances of Classes that are log hosts.
	module InstanceMethods

		### Fetch the key of the log host the instance of this client targets
		def log_host_key
			return self.class.log_host_key
		end


		### Delegate to the class's logger.
		def log
			@__log ||= Loggability[ self.class ].proxy_for( self )
		end

	end # module InstanceMethods

end # module Loggability::LogClient

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
loggability-0.11.0 lib/loggability/logclient.rb
loggability-0.10.1 lib/loggability/logclient.rb
loggability-0.10.0 lib/loggability/logclient.rb
loggability-0.9.0 lib/loggability/logclient.rb
loggability-0.9.0.pre.73 lib/loggability/logclient.rb
loggability-0.8.1 lib/loggability/logclient.rb
loggability-0.8.0 lib/loggability/logclient.rb
loggability-0.8.0.pre.65 lib/loggability/logclient.rb