Class: PDK::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/pdk/logger.rb

Constant Summary collapse

WRAP_COLUMN_LIMIT =
78

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pdk/logger.rb', line 8

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 = /(.{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

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pdk/logger.rb', line 42

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

#enable_debug_outputObject



38
39
40
# File 'lib/pdk/logger.rb', line 38

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

#warn_once(*args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/pdk/logger.rb', line 30

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