lib/lumber/lumber.rb in lumber-0.10.0 vs lib/lumber/lumber.rb in lumber-0.10.2

- old
+ new

@@ -61,10 +61,14 @@ @@registered_loggers = {} self.register_inheritance_handler() end + def self.find_or_create_logger(fullname) + Log4r::Logger[fullname] || Log4r::Logger.new(fullname) + end + # Makes :logger exist independently for subclasses and sets that logger # to one that inherits from base_class for each subclass as it is created. # This allows you to have a finer level of control over logging, for example, # put just a single class, or hierarchy of classes, into debug log level # @@ -88,11 +92,11 @@ [:class_attribute, :class_inheritable_accessor].each do |class_attribute_method| if clazz.respond_to? class_attribute_method clazz.class_eval do send class_attribute_method, :logger - self.logger = Log4r::Logger.new(class_logger_fullname) + self.logger = Lumber.find_or_create_logger(class_logger_fullname) end break end end @@ -141,11 +145,11 @@ class_attribute :logger else class_inheritable_accessor :logger end - self.logger = Log4r::Logger.new(logger_name) + self.logger = Lumber.find_or_create_logger(logger_name) class << self # Prevent rails from overwriting our logger def cattr_accessor_with_lumber_log4r(*syms) @@ -166,10 +170,11 @@ parent = clazz.superclass while ! parent.nil? parent_logger_name = parent.logger.fullname rescue '' parent_is_registered = @@registered_loggers.values.find {|v| parent_logger_name.index(v) == 0} if parent_is_registered && parent.method_defined?(:logger=) - clazz.logger = Log4r::Logger.new("#{parent_logger_name}::#{clazz.name.nil? ? 'anonymous' : clazz.name.split('::').last}") + fullname = "#{parent_logger_name}::#{clazz.name.nil? ? 'anonymous' : clazz.name.split('::').last}" + clazz.logger = Lumber.find_or_create_logger(fullname) break end parent = parent.superclass end end \ No newline at end of file