Class: Bolt::Outputter::Logger

Inherits:
Bolt::Outputter show all
Defined in:
lib/bolt/outputter/logger.rb

Instance Method Summary collapse

Methods inherited from Bolt::Outputter

for_format, #indent, #print_error, #print_message, #spin, #start_spin, #stop_spin

Constructor Details

#initialize(verbose, trace) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
# File 'lib/bolt/outputter/logger.rb', line 8

def initialize(verbose, trace)
  super(false, verbose, trace, false)
  @logger = Bolt::Logger.logger(self)
end

Instance Method Details

#handle_event(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bolt/outputter/logger.rb', line 13

def handle_event(event)
  case event[:type]
  when :step_start
    log_step_start(**event)
  when :step_finish
    log_step_finish(**event)
  when :plan_start
    log_plan_start(event)
  when :plan_finish
    log_plan_finish(event)
  when :container_start
    log_container_start(event)
  when :container_finish
    log_container_finish(event)
  end
end

#log_container_finish(event) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/bolt/outputter/logger.rb', line 60

def log_container_finish(event)
  result = event[:result]
  if result.success?
    @logger.info("Finished: run container '#{result.object}' succeeded.")
  else
    @logger.info("Finished: run container '#{result.object}' failed.")
  end
end

#log_container_start(event) ⇒ Object



56
57
58
# File 'lib/bolt/outputter/logger.rb', line 56

def log_container_start(event)
  @logger.info("Starting: run container '#{event[:image]}'")
end

#log_plan_finish(event) ⇒ Object



50
51
52
53
54
# File 'lib/bolt/outputter/logger.rb', line 50

def log_plan_finish(event)
  plan = event[:plan]
  duration = event[:duration]
  @logger.info("Finished: plan #{plan} in #{duration.round(2)} sec")
end

#log_plan_start(event) ⇒ Object



45
46
47
48
# File 'lib/bolt/outputter/logger.rb', line 45

def log_plan_start(event)
  plan = event[:plan]
  @logger.info("Starting: plan #{plan}")
end

#log_step_finish(description:, result:, duration:, **_kwargs) ⇒ Object



39
40
41
42
43
# File 'lib/bolt/outputter/logger.rb', line 39

def log_step_finish(description:, result:, duration:, **_kwargs)
  failures = result.error_set.length
  plural = failures == 1 ? '' : 's'
  @logger.info("Finished: #{description} with #{failures} failure#{plural} in #{duration.round(2)} sec")
end

#log_step_start(description:, targets:, **_kwargs) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/bolt/outputter/logger.rb', line 30

def log_step_start(description:, targets:, **_kwargs)
  target_str = if targets.length > 5
                 "#{targets.count} targets"
               else
                 targets.map(&:safe_name).join(', ')
               end
  @logger.info("Starting: #{description} on #{target_str}")
end