lib/capistrano/measure/log_reporter.rb in capistrano-measure-0.8.1 vs lib/capistrano/measure/log_reporter.rb in capistrano-measure-0.9.0

- old
+ new

@@ -1,23 +1,28 @@ -require 'colored' +require 'colorized_string' require 'logger' module Capistrano module Measure class LogReporter - ALERT_TRASHOLD = 60 - WARNING_TRASHOLD = 30 - def initialize(logger=nil) - @logger = logger || ::Logger.new(STDOUT) + attr_reader :alert_threshold, :warning_threshold + + DEFALUT_ALERT_THRESHOLD = 60 + DEFAULT_WARNING_THRESHOLD = 30 + + 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 def render(events) return if events.to_a.empty? log_sepertor - log " Performance Report".green + log ColorizedString[" Performance Report"].green log_sepertor events.each do |event| log "#{'..' * event.indent}#{event.name} #{colorize_time(event.elapsed_time)}" end @@ -25,21 +30,23 @@ end private def log_sepertor - log "==========================================================" + log "=" * 60 end def log(text) @logger.info text end def colorize_time(time_spent) return if time_spent.nil? - color = (time_spent > ALERT_TRASHOLD ? :red : (time_spent > WARNING_TRASHOLD ? :yellow : :green)) - "#{time_spent}s".send(color) + ColorizedString["#{time_spent}s"].colorize(color(time_spent)) end + def color(time_spent) + (time_spent > alert_threshold ? :red : (time_spent > warning_threshold ? :yellow : :green)) + end end end end