Module: Krane::DeferredSummaryLogging

Included in:
FormattedLogger
Defined in:
lib/krane/deferred_summary_logging.rb

Overview

Adds the methods krane 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.



9
10
11
# File 'lib/krane/deferred_summary_logging.rb', line 9

def summary
  @summary
end

Instance Method Details

#blank_line(level = :info) ⇒ Object



20
21
22
# File 'lib/krane/deferred_summary_logging.rb', line 20

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

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



29
30
31
32
33
34
35
36
# File 'lib/krane/deferred_summary_logging.rb', line 29

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



10
11
12
13
# File 'lib/krane/deferred_summary_logging.rb', line 10

def initialize(*args)
  reset
  super
end

#phase_heading(phase_name) ⇒ Object



24
25
26
27
# File 'lib/krane/deferred_summary_logging.rb', line 24

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/krane/deferred_summary_logging.rb', line 39

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

  if (actions_sentence = summary.actions_sentence.presence)
    public_send(level, actions_sentence)
    blank_line(level)
  end

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

#resetObject



15
16
17
18
# File 'lib/krane/deferred_summary_logging.rb', line 15

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