class Capistrano::Measure::LogReporter

Constants

DEFALUT_ALERT_THRESHOLD
DEFAULT_WARNING_THRESHOLD

Attributes

alert_threshold[R]
warning_threshold[R]

Public Class Methods

new(logger, config) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 13
def initialize(logger, config)
  @logger = logger
  @alert_threshold = config.fetch(:alert_threshold, DEFALUT_ALERT_THRESHOLD)
  @warning_threshold = config.fetch(:warning_threshold, DEFAULT_WARNING_THRESHOLD)
end

Public Instance Methods

render(events) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 19
def render(events)
  return if events.to_a.empty?

  with_layout do
    events.each do |event|
      log "#{'..' * event.indent}#{event.name} #{colorize_time(event.elapsed_time)}"
    end
  end
end
render_error(message) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 29
def render_error(message)
  with_layout do
    @logger.error message
  end
end

Private Instance Methods

color(time_spent) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 58
def color(time_spent)
  (time_spent > alert_threshold ? :red : (time_spent > warning_threshold ? :yellow : :green))
end
colorize_time(time_spent) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 53
def colorize_time(time_spent)
  return if time_spent.nil?
  ColorizedString["#{time_spent}s"].colorize(color(time_spent))
end
log(text) click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 49
def log(text)
  @logger.info text
end
log_sepertor() click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 45
def log_sepertor
  log "=" * 60
end
with_layout() { || ... } click to toggle source
# File lib/capistrano/measure/log_reporter.rb, line 37
def with_layout
  log_sepertor
  log ColorizedString["  Performance Report"].green
  log_sepertor
  yield
  log_sepertor
end