Sha256: 7f29b342e47f500629689214f55df7913076679976e6515b61c8861b7c9dee97

Contents?: true

Size: 797 Bytes

Versions: 17

Compression:

Stored size: 797 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(debug_output)
          @logger.formatter = proc do |severity, datetime, progname, msg|
            "#{severity}: #{msg}\n"
          end
        else
          @logger = DisabledLogger.new
        end

        return @logger
      end

      def debug_output
        if ENV['PSD_DEBUG']
          ENV['PSD_DEBUG'] == 'STDOUT' ? STDOUT : ENV['PSD_DEBUG']
        end

        STDOUT
      end
    end
  end

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
psd-1.4.3 lib/psd/logger.rb
psd-1.4.2 lib/psd/logger.rb
psd-1.4.1 lib/psd/logger.rb
psd-1.4.0 lib/psd/logger.rb
psd-1.3.3 lib/psd/logger.rb
psd-1.3.2 lib/psd/logger.rb
psd-1.3.0 lib/psd/logger.rb
psd-1.2.2 lib/psd/logger.rb
psd-1.2.1 lib/psd/logger.rb
psd-1.2.0 lib/psd/logger.rb
psd-1.1.1 lib/psd/logger.rb
psd-1.1.0 lib/psd/logger.rb
psd-1.0.0 lib/psd/logger.rb
psd-0.4.2 lib/psd/logger.rb
psd-0.4.1 lib/psd/logger.rb
psd-0.4.0 lib/psd/logger.rb
psd-0.3.5 lib/psd/logger.rb