Sha256: 121133b0ec0ba03a02949a4748e5d8e2a90b18bba53e5b681795182a0eca0285

Contents?: true

Size: 634 Bytes

Versions: 3

Compression:

Stored size: 634 Bytes

Contents

require 'logger'

class PSD
  module Logger
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      attr_accessor :debug

      def logger
        return @logger if @logger

        if debug || ENV['PSD_DEBUG']
          @logger = ::Logger.new(STDOUT)
          @logger.formatter = proc do |severity, datetime, progname, msg|
            "#{severity}: #{msg}\n"
          end
        else
          @logger = DisabledLogger.new
        end

        return @logger
      end
    end
  end

  class DisabledLogger
    def method_missing(method, *args, &block)
      # silence
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
psd-1.5.0 lib/psd/logger.rb
psd-1.4.5 lib/psd/logger.rb
psd-1.4.4 lib/psd/logger.rb