Class: MCollective::Util::Playbook::Puppet_Logger

Inherits:
Logger::Console_logger show all
Defined in:
lib/mcollective/util/playbook/puppet_logger.rb

Instance Attribute Summary collapse

Attributes inherited from Logger::Base

#active_level

Instance Method Summary collapse

Methods inherited from Logger::Console_logger

#color, #colorize, #set_logging_level, #valid_levels

Methods inherited from Logger::Base

#cycle_level, #reopen, #set_level

Constructor Details

#initialize(playbook) ⇒ Puppet_Logger

Returns a new instance of Puppet_Logger.



9
10
11
12
13
14
# File 'lib/mcollective/util/playbook/puppet_logger.rb', line 9

def initialize(playbook)
  @playbook = playbook
  @report = playbook.report

  super()
end

Instance Attribute Details

#scope=(value) ⇒ Object (writeonly)

Sets the attribute scope

Parameters:

  • value

    the value to set the attribute scope to.



7
8
9
# File 'lib/mcollective/util/playbook/puppet_logger.rb', line 7

def scope=(value)
  @scope = value
end

Instance Method Details

#log(level, from, msg, normal_output = $stderr, last_resort_output = $stderr) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mcollective/util/playbook/puppet_logger.rb', line 20

def log(level, from, msg, normal_output=$stderr, last_resort_output=$stderr)
  return unless should_show?(level)

  logmethod = case level
              when :info
                :notice
              when :warn
                :warning
              when :error
                :err
              when :fatal
                :crit
              else
                :debug
              end

  if @scope
    Puppet::Util::Log.log_func(@scope, logmethod, [msg])
  else
    Puppet.send(logmethod, msg)
  end
end

#should_show?(level) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/mcollective/util/playbook/puppet_logger.rb', line 43

def should_show?(level)
  return true unless level == :info

  !caller(2..5).grep(/playbook/).empty?
end

#startObject



16
17
18
# File 'lib/mcollective/util/playbook/puppet_logger.rb', line 16

def start
  set_level(@playbook.loglevel.intern)
end