Sha256: 985d03a6927d1e29ef3359c9c35394126eba30f202f62ba29988c189ad04a37b

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'loggr/adapter/abstract'
require 'loggr/support/annotations'

module Loggr
  module Adapter

    # Silences all logging operations, nothing is written at all.
    #
    class NOPAdapter < AbstractAdapter

      class NOPLogger
        # Has no impact anyway :)
        attr_accessor :level

        # Just to ensure compatiability with AS::BufferedLogger
        attr_reader :auto_flushing, :flush, :close

        # Support fuer Annotations wie `tagged` und `mapped`.
        include Loggr::Support::Annotations::NOPSupport

        # Yields empty implementations for all severities
        %w{trace debug info warn error fatal}.each do |severity|
          class_eval <<-EOT, __FILE__, __LINE__ + 1
            def #{severity}(*args, &block)   # def debug(*args, &block)
            end                              # end

            def #{severity}?                 # def debug?
              false                          #   false
            end                              # end
          EOT
        end
      end

      # Get single NOPLogger instance
      def logger(name, options = {})
        @logger ||= NOPLogger.new
      end
    end

    # THE instance
    NOP = NOPAdapter.new
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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