Sha256: e052ba95e218f0fe08d773ba21dcd4b91a188b19e4f9d775a49656fa4a919c3f

Contents?: true

Size: 925 Bytes

Versions: 4

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

# Scope Rails
module R2OAS
  module TaskLogging
    def task(*args, &block)
      Rake::Task.define_task(*args) do |task|
        if block_given?
          debug_log task, "[#{task.name}] started"
          begin
            block.call(task)
            debug_log task, "[#{task.name}] finished"
          rescue StandardError => e
            debug_log task, "[#{task.name}] failed"
            raise e
          end
        end
      end
    end

    private

    def start
      logger.info '[R2-OAS] start'
      yield
      logger.info '[R2-OAS] end'
    end

    def logger
      R2OAS.logger
    end

    def set_info_level
      R2OAS.logger.level = StdoutLogger::INFO
    end

    def set_debug_level
      R2OAS.logger.level = StdoutLogger::DEBUG
    end

    def debug_log(task, message)
      R2OAS.logger.debug message.to_s unless task.name == 'routes:oas:debug'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
r2-oas-0.3.2 lib/r2-oas/task_logging.rb
r2-oas-0.3.1 lib/r2-oas/task_logging.rb
r2-oas-0.3.0 lib/r2-oas/task_logging.rb
r2-oas-0.2.0 lib/r2-oas/task_logging.rb