more tweaks and stuff

This commit is contained in:
John Bintz 2012-01-21 13:02:11 -05:00
parent d29ece1ee2
commit 5bb15600b7
3 changed files with 20 additions and 12 deletions

View File

@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "capybara-rails-log-inspection"
gem.require_paths = ["lib"]
gem.version = Capybara::Rails::LogInspection::VERSION
gem.version = Capybara::RailsLogInspection::VERSION
gem.add_runtime_dependency 'term-ansicolor'
end

View File

@ -1,8 +1,6 @@
module Capybara
module Rails
module LogInspection
VERSION = "0.0.1"
end
module RailsLogInspection
VERSION = "0.0.1"
end
end

View File

@ -13,27 +13,34 @@ module Capybara
logger
end
attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level
attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level, :filter_request_starts
def default_log_level
Logger::WARN
Logger::INFO
end
def rack_log_level
Logger::WARN
end
def filter_request_starts
@filter_request_starts ||= true
end
def clean_rack_output(lines)
lines.collect(&:strip).reject { |line| line.empty? || (filter_request_starts && line[%r{^Started }]) }
end
def backtrace_clean_patterns
@backtrace_clean_patterns ||= [ %r{/gems/}, %r{/ruby/1} ]
end
def clean_backtrace(exception)
exception.backtrace.reject { |line| line.empty? || backtrace_clean_patterns.any? { |pattern| line[pattern] } }
exception.backtrace.collect(&:strip).reject { |line| line.empty? || backtrace_clean_patterns.any? { |pattern| line[pattern] } }
end
def add_backtrace(exception)
clean_backtrace(exception).each { |line| logger_target << " #{line}\n" }
logger_target << "\n"
clean_backtrace(exception).each { |line| logger_target << " #{line}" }
end
end
@ -45,8 +52,11 @@ module Capybara
def output_logs(target = $stderr)
Capybara::RailsLogInspection.logger_target.rewind
data = Capybara::RailsLogInspection.logger_target.read
target.print(Term::ANSIColor.red, data, Term::ANSIColor.reset) if !data.empty?
lines = Capybara::RailsLogInspection.logger_target.read.lines
Capybara::RailsLogInspection.clean_rack_output(lines).each do |line|
target.puts(Term::ANSIColor.red, line, Term::ANSIColor.reset)
end
reset_logs
end