Sha256: 17a526ced058032966a00ae9a7543cea2ef33573f3b9ae1832c788bdb53cf70c

Contents?: true

Size: 1.46 KB

Versions: 40

Compression:

Stored size: 1.46 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)
        @logger = Logging.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)
        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.notice("Starting: plan #{plan}")
      end

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

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
bolt-2.23.0 lib/bolt/outputter/logger.rb
bolt-2.22.0 lib/bolt/outputter/logger.rb
bolt-2.21.0 lib/bolt/outputter/logger.rb
bolt-2.20.0 lib/bolt/outputter/logger.rb
bolt-2.19.0 lib/bolt/outputter/logger.rb
bolt-2.18.0 lib/bolt/outputter/logger.rb
bolt-2.17.0 lib/bolt/outputter/logger.rb
bolt-2.16.0 lib/bolt/outputter/logger.rb
bolt-2.15.0 lib/bolt/outputter/logger.rb
bolt-2.14.0 lib/bolt/outputter/logger.rb
bolt-2.13.0 lib/bolt/outputter/logger.rb
bolt-2.12.0 lib/bolt/outputter/logger.rb
bolt-2.11.1 lib/bolt/outputter/logger.rb
bolt-2.11.0 lib/bolt/outputter/logger.rb
bolt-2.10.0 lib/bolt/outputter/logger.rb
bolt-2.9.0 lib/bolt/outputter/logger.rb
bolt-2.8.0 lib/bolt/outputter/logger.rb
bolt-2.7.0 lib/bolt/outputter/logger.rb
bolt-2.6.0 lib/bolt/outputter/logger.rb
bolt-2.5.0 lib/bolt/outputter/logger.rb