Sha256: b46424a8b979e9eb10e4ad66c4cbf6b6c1b976f9b0ab2578fcb3c8f8aa48daea

Contents?: true

Size: 758 Bytes

Versions: 3

Compression:

Stored size: 758 Bytes

Contents

module Loggr
  module Adapter

    # A basically abstract base class for logger backend
    # implementations, provides a default implementation for MDC (hash & thread local based).
    #
    # Ensure to implement `#logger`.
    #
    class AbstractAdapter

      # Implement which creates a new instance of a logger.
      def logger(name, options = {})
        raise "#{self.class.name}#logger is declared `abstract': implement #logger method"
      end

      # Use a simple thread local hash as fake MDC, because it's
      # not supported by the logger anyway - but it should be available
      # for consistency and usage.
      def mdc
        mdc_key = "#{self.class.name}.mdc"
        Thread.current[mdc_key] ||= Hash.new
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loggr-1.1.2 lib/loggr/adapter/abstract.rb
loggr-1.1.1 lib/loggr/adapter/abstract.rb
loggr-1.1.0 lib/loggr/adapter/abstract.rb