Sha256: 9d9678a57772736d2a21bb7adeda9b47c34e50f73d8798bb248639e2a504ed8c

Contents?: true

Size: 2 KB

Versions: 13

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

require 'bolt/pal'

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

      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

      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

      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

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

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

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

      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bolt-3.12.0 lib/bolt/outputter/logger.rb
bolt-3.11.0 lib/bolt/outputter/logger.rb
bolt-3.10.0 lib/bolt/outputter/logger.rb
bolt-3.9.2 lib/bolt/outputter/logger.rb
bolt-3.9.1 lib/bolt/outputter/logger.rb
bolt-3.9.0 lib/bolt/outputter/logger.rb
bolt-3.8.1 lib/bolt/outputter/logger.rb
bolt-3.8.0 lib/bolt/outputter/logger.rb
bolt-3.7.1 lib/bolt/outputter/logger.rb
bolt-3.7.0 lib/bolt/outputter/logger.rb
bolt-3.6.1 lib/bolt/outputter/logger.rb
bolt-3.6.0 lib/bolt/outputter/logger.rb
bolt-3.5.0 lib/bolt/outputter/logger.rb