Class: MCollective::Util::Playbook::Playbook_Logger

Inherits:
Logger::Console_logger show all
Defined in:
lib/mcollective/util/playbook/playbook_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) ⇒ Playbook_Logger

Returns a new instance of Playbook_Logger.



9
10
11
12
13
14
# File 'lib/mcollective/util/playbook/playbook_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/playbook_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
# File 'lib/mcollective/util/playbook/playbook_logger.rb', line 20

def log(level, from, msg, normal_output=$stderr, last_resort_output=$stderr)
  if @playbook.loglevel != "debug"
    if should_show?
      console_from = "%s#%-25s" % [@playbook.name, @playbook.context]
    else
      level = :debug
    end
  end

  if @known_levels.index(level) >= @known_levels.index(@active_level)
    r_time = Time.now
    s_time = r_time.strftime("%H:%M:%S")

    @report.append_log(r_time, level, from, msg)

    normal_output.puts("%s %s: %s %s" % [colorize(level, level[0].capitalize), s_time, console_from, msg])
  end
rescue
  last_resort_output.puts("%s: %s" % [level, msg])
end

#should_show?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/mcollective/util/playbook/playbook_logger.rb', line 41

def should_show?
  !caller(1..5).grep(/playbook/).empty?
end

#startObject



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

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