Sha256: e61ca40ab078d1ff0bcce3919dabd1c60dad6c928d89ee38da87fe3ed78fffca

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

require 'active_support/concern'
require 'active_support/core_ext/module/delegation'

module Lumber

  # Include this module to add a logger accessible from both class and instance methods.
  # A logger hierarchy will be created if the class including this module is nested
  module LoggerSupport
    extend ActiveSupport::Concern

    included do

      delegate :logger, :to => "self.class"

    end

    module ClassMethods


      def logger
        # This should probably be synchronized, but don't want to
        # incur the performance hit on such a heavily used method.
        # I think the worst case is that it'll just get assigned
        # multiple times, but it'll get the same reference because
        # Lumber.logger has a lock
        @lumber_logger ||= Lumber.logger_for(self)
      end

      def logger=(logger)
        @lumber_logger = logger
      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lumber-1.1.3 lib/lumber/logger_support.rb
lumber-1.1.2 lib/lumber/logger_support.rb
lumber-1.1.1 lib/lumber/logger_support.rb
lumber-1.1.0 lib/lumber/logger_support.rb