Sha256: b43fac36647eb768a591f196f991f7f15e192651ac20f8ba587ca3b80870e053

Contents?: true

Size: 1.03 KB

Versions: 16

Compression:

Stored size: 1.03 KB

Contents

require 'logger'
require 'pdk'

module PDK
  class Logger < ::Logger
    WRAP_COLUMN_LIMIT = 78

    def initialize
      super(STDERR)
      @sent_messages = {}

      # TODO: Decide on output format.
      self.formatter = proc do |severity, _datetime, _progname, msg|
        prefix = "pdk (#{severity}): "
        if msg.is_a?(Hash)
          if msg.fetch(:wrap, false)
            wrap_pattern = %r{(.{1,#{WRAP_COLUMN_LIMIT - prefix.length}})(\s+|\Z)}
            "#{prefix}#{msg[:text].gsub(wrap_pattern, "\\1\n#{' ' * prefix.length}")}\n"
          else
            "#{prefix}#{msg[:text]}\n"
          end
        else
          "#{prefix}#{msg}\n"
        end
      end

      self.level = ::Logger::INFO
    end

    def warn_once(*args)
      hash = args.inspect.hash
      return if (@sent_messages[::Logger::WARN] ||= {}).key?(hash)
      @sent_messages[::Logger::WARN][hash] = true
      warn(*args)
    end

    def enable_debug_output
      self.level = ::Logger::DEBUG
    end

    def debug?
      level == ::Logger::DEBUG
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pdk-2.7.1 lib/pdk/logger.rb
pdk-2.7.0 lib/pdk/logger.rb
pdk-2.6.1 lib/pdk/logger.rb
pdk-2.6.0 lib/pdk/logger.rb
pdk-2.5.0 lib/pdk/logger.rb
pdk-2.3.0 lib/pdk/logger.rb
pdk-2.2.0 lib/pdk/logger.rb
pdk-2.1.1 lib/pdk/logger.rb
pdk-2.1.0 lib/pdk/logger.rb
pdk-2.0.0 lib/pdk/logger.rb
pdk-1.18.1 lib/pdk/logger.rb
pdk-1.18.0 lib/pdk/logger.rb
pdk-1.17.0 lib/pdk/logger.rb
pdk-1.16.0 lib/pdk/logger.rb
pdk-1.15.0 lib/pdk/logger.rb
pdk-1.14.1 lib/pdk/logger.rb