Sha256: 4d157fdcc86289bc0f03978581390123371aa42c046512c25ac16865610f0d0f

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 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 clients.
	module InstanceMethods

		### Unset the logger proxy for copies of the logged object.
		def initialize_copy( other )
			super
			@__log = nil
		end


		### 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

5 entries across 5 versions & 1 rubygems

Version Path
loggability-0.14.0 lib/loggability/logclient.rb
loggability-0.13.0 lib/loggability/logclient.rb
loggability-0.12.0 lib/loggability/logclient.rb
loggability-0.12.0.pre20161214121603 lib/loggability/logclient.rb
loggability-0.12.0.pre20161212115530 lib/loggability/logclient.rb