Module: R10K::Logging

Defined Under Namespace

Classes: TerminalOutputter

Constant Summary collapse

LOG_LEVELS =
%w{DEBUG2 DEBUG1 DEBUG INFO NOTICE WARN ERROR FATAL}

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.formatterObject (readonly)

Returns the value of attribute formatter.



83
84
85
# File 'lib/r10k/logging.rb', line 83

def formatter
  @formatter
end

.levelObject

Returns the value of attribute level.



78
79
80
# File 'lib/r10k/logging.rb', line 78

def level
  @level
end

.outputterObject (readonly)

Returns the value of attribute outputter.



88
89
90
# File 'lib/r10k/logging.rb', line 88

def outputter
  @outputter
end

Class Method Details

.debug_formatterObject



94
95
96
# File 'lib/r10k/logging.rb', line 94

def debug_formatter
  Log4r::PatternFormatter.new(:pattern => '[%d - %l] %m')
end

.default_formatterObject



90
91
92
# File 'lib/r10k/logging.rb', line 90

def default_formatter
  Log4r::PatternFormatter.new(:pattern => '%l\t -> %m')
end

.default_outputterObject



98
99
100
# File 'lib/r10k/logging.rb', line 98

def default_outputter
  R10K::Logging::TerminalOutputter.new('terminal', $stderr, :level => self.level, :formatter => formatter)
end

.parse_level(input) ⇒ Integer, NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert the input to a valid Log4r log level

Parameters:

  • input (String, TrueClass)

    The level to parse. If TrueClass then Log4r::INFO will be returned (indicating a generic raised verbosity), if a string it will be parsed either as a numeric value or a textual log level.

Returns:

  • (Integer, NilClass)

    The numeric log level, or nil if the log level is invalid.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/r10k/logging.rb', line 40

def parse_level(input)
  case input
  when TrueClass
    Log4r::INFO
  when /\A\d+\Z/
    Integer(input)
  when String
    const_name = input.upcase
    if LOG_LEVELS.include?(const_name)
      begin
        Log4r.const_get(const_name.to_sym)
      rescue NameError
      end
    end
  end
end

Instance Method Details

#loggerObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/r10k/logging.rb', line 16

def logger
  if @logger.nil?
    name = logger_name
    if Log4r::Logger[name]
      @logger = Log4r::Logger[name]
    else
      @logger = Log4r::Logger.new(name)
      @logger.add(R10K::Logging.outputter)
    end
  end
  @logger
end

#logger_nameObject



12
13
14
# File 'lib/r10k/logging.rb', line 12

def logger_name
  self.class.to_s
end