module R2OAS::TaskLogging

Public Instance Methods

task(*args, &block) click to toggle source
# File lib/r2-oas/task_logging.rb, line 6
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 Instance Methods

debug_log(task, message) click to toggle source
# File lib/r2-oas/task_logging.rb, line 37
def debug_log(task, message)
  R2OAS.logger.debug message.to_s unless task.name == 'routes:oas:debug'
end
logger() click to toggle source
# File lib/r2-oas/task_logging.rb, line 29
def logger
  R2OAS.logger
end
set_debug_level() click to toggle source
# File lib/r2-oas/task_logging.rb, line 33
def set_debug_level
  R2OAS.logger.level = StdoutLogger::DEBUG
end
start(initial = '[R2-OAS]') { || ... } click to toggle source
# File lib/r2-oas/task_logging.rb, line 23
def start(initial = '[R2-OAS]')
  logger.info "#{initial} start"
  yield
  logger.info "#{initial} end"
end