lib/loggability.rb in loggability-0.3.0 vs lib/loggability.rb in loggability-0.4.0

- old
+ new

@@ -7,14 +7,14 @@ # A mixin that provides a top-level logging subsystem based on Logger. module Loggability # Package version constant - VERSION = '0.3.0' + VERSION = '0.4.0' # VCS revision - REVISION = %q$Revision: 7b6ef57de872 $ + REVISION = %q$Revision: 2615ed217d34 $ # The key for the global logger (Loggability's own logger) GLOBAL_KEY = :__global__ # The methods that are delegated across all loggers @@ -59,10 +59,19 @@ vstring << " (build %s)" % [ REVISION[/: ([[:xdigit:]]+)/, 1] || '0' ] if include_buildnum return vstring end + ### Cast the given +device+ to a Loggability::Logger, if possible, and return it. If + ### it can't be converted, raises a ArgumentError. + def self::Logger( device ) + return device if device.is_a?( Loggability::Logger ) + return Loggability::Logger.from_std_logger( device ) if device.is_a?( ::Logger ) + return Loggability::Logger.new( device ) + end + + ### Register the specified +host+ as a log host. It should already have been extended ### with LogHostMethods. def self::register_loghost( host ) key = host.log_host_key if self.log_hosts.key?( key ) @@ -186,15 +195,22 @@ # The logger that will be used when the logging subsystem is reset attr_accessor :default_logger # The logger that's currently in effect - attr_accessor :logger + attr_reader :logger alias_method :log, :logger - alias_method :log=, :logger= # The key associated with the logger for this host attr_accessor :log_host_key + + + ### Set the logger associated with the LogHost to +newlogger+. If +newlogger+ isn't a + ### Loggability::Logger, it will be converted to one. + def logger=( newlogger ) + @logger = Loggability::Logger( newlogger ) + end + alias_method :log=, :logger= end # module LogHost #