Skip to content
Browse files

add debug mode

  • Loading branch information...
1 parent b43e5cb commit c55c00fdce33064edf372cd326b4ef296e3a90f3 @flyerhzm committed Mar 4, 2010
Showing with 10 additions and 1 deletion.
  1. +2 −1 README.md
  2. +4 −0 bin/seo_checker
  3. +4 −0 lib/seo_checker.rb
View
3 README.md
@@ -29,11 +29,12 @@ It is strongly recommand to check seo in development environment. If you want to
Usage: seo_checker [OPTIONS] website_url
-b, --batch BATCH_SIZE get a batch size of pages
-i, --interval INTERVAL_TIME interval time between two batches
+ --debug
-h, --help Show this message
</code></pre>
For example:
<pre><code>seo_checker http://localhost:3000</code></pre>
-<pre><code>seo_checker http://yoursite.com -b 10 -i 1</code></pre>
+<pre><code>seo_checker http://yoursite.com --debug -b 10 -i 1</code></pre>
View
4 bin/seo_checker
@@ -15,6 +15,10 @@ OptionParser.new do |opts|
options[:interval_time] = interval
end
+ opts.on('--debug') do
+ options[:logger] = true
+ end
+
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
View
4 lib/seo_checker.rb
@@ -1,4 +1,5 @@
require 'enumerator'
+require 'logger'
require 'net/http'
require 'uri'
@@ -19,6 +20,7 @@ def initialize(url, options={})
@unreachables = []
@batch_size = options[:batch_size] ? options[:batch_size].to_i : nil
@interval_time = options[:interval_time].to_i
+ @logger = options[:logger] == true ? Logger.new(STDOUT) : options[:logger]
end
def check
@@ -34,6 +36,7 @@ def check
def check_sitemap
#TODO: allow manual sitemap file
+ @logger.debug "checking sitemap file" if @logger
uri = URI.parse(@url)
uri.path = '/sitemap.xml'
response = get_response(uri)
@@ -48,6 +51,7 @@ def check_location
@batch_size ||= @locations.size
@locations.each_slice(@batch_size) do |batch_locations|
batch_locations.each do |location|
+ @logger.debug "checking #{location}" if @logger
response = get_response(URI.parse(location))
if response.is_a? Net::HTTPSuccess
if response.body =~ %r{<head>(.*?)</head>}m

0 comments on commit c55c00f

Please sign in to comment.
Something went wrong with that request. Please try again.