Sha256: 9ff918e9e07d7155f746daa246caca93367b1a913d770fd9f15a549ac8136894

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

# -*- ruby -*-
# vim: set nosta noet ts=4 sw=4:
# frozen_string_literal: true

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

7 entries across 7 versions & 1 rubygems

Version Path
loggability-0.18.2 lib/loggability/logclient.rb
loggability-0.18.1 lib/loggability/logclient.rb
loggability-0.18.0 lib/loggability/logclient.rb
loggability-0.17.0 lib/loggability/logclient.rb
loggability-0.16.0 lib/loggability/logclient.rb
loggability-0.15.1 lib/loggability/logclient.rb
loggability-0.15.0.pre20190714094638 lib/loggability/logclient.rb