Module: KubernetesDeploy::DeferredSummaryLogging

Included in:
FormattedLogger
Defined in:
lib/kubernetes-deploy/deferred_summary_logging.rb

Overview

Adds the methods kubernetes-deploy requires to your logger class. These methods include helpers for logging consistent headings, as well as facilities for displaying key information later, in a summary section, rather than when it occurred.

Defined Under Namespace

Classes: DeferredSummary

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#summaryObject (readonly)

Returns the value of attribute summary.



7
8
9
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 7

def summary
  @summary
end

Instance Method Details

#blank_line(level = :info) ⇒ Object



18
19
20
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 18

def blank_line(level = :info)
  public_send(level, "")
end

#heading(text, secondary_msg = '', secondary_msg_color = :cyan) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 27

def heading(text, secondary_msg = '', secondary_msg_color = :cyan)
  padding = (100.0 - (text.length + secondary_msg.length)) / 2
  blank_line
  part1 = ColorizedString.new("#{'-' * padding.floor}#{text}").cyan
  part2 = ColorizedString.new(secondary_msg).colorize(secondary_msg_color)
  part3 = ColorizedString.new('-' * padding.ceil).cyan
  info(part1 + part2 + part3)
end

#initialize(*args) ⇒ Object



8
9
10
11
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 8

def initialize(*args)
  reset
  super
end

#phase_heading(phase_name) ⇒ Object



22
23
24
25
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 22

def phase_heading(phase_name)
  @current_phase += 1
  heading("Phase #{@current_phase}: #{phase_name}")
end

Outputs the deferred summary information saved via @logger.summary.add_action and @logger.summary.add_paragraph



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 37

def print_summary(status)
  status_string = status.to_s.humanize.upcase
  if status == :success
    heading("Result: ", status_string, :green)
    level = :info
  elsif status == :timed_out
    heading("Result: ", status_string, :yellow)
    level = :fatal
  else
    heading("Result: ", status_string, :red)
    level = :fatal
  end

  public_send(level, summary.actions_sentence)
  summary.paragraphs.each do |para|
    blank_line(level)
    msg_lines = para.split("\n")
    msg_lines.each { |line| public_send(level, line) }
  end
end

#resetObject



13
14
15
16
# File 'lib/kubernetes-deploy/deferred_summary_logging.rb', line 13

def reset
  @summary = DeferredSummary.new
  @current_phase = 0
end