From c560a0d20eca183111e53df5bc0b53db56862cdf Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Mon, 23 Apr 2012 00:19:42 -0700 Subject: [PATCH] Add timing info to render logging, and document why we use thin instead of webrick --- middleman-core/lib/middleman-core/application.rb | 15 +++++++-------- .../lib/middleman-core/sitemap/resource.rb | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index f34b98e9..84b9ad4c 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -378,6 +378,8 @@ module Middleman # # @private def process_request + start_time = Time.now + # Normalize the path and add index if we're looking at a directory @original_path = env["PATH_INFO"].dup @escaped_path = @original_path.gsub("%20", " ") @@ -418,7 +420,7 @@ module Middleman end # End the request - puts "== Finishing Request: #{self.current_path}" if logging? + puts "== Finishing Request: #{self.current_path} (#{(Time.now - start_time).round(2)}s)" if logging? halt res.finish end @@ -531,28 +533,25 @@ module Middleman # @param [Hash] options to pass to Rack::Server.new # @return [Rack::Server] def start_server(options={}) - require "webrick" - opts = { :Port => options[:port] || 4567, :Host => options[:host] || "0.0.0.0", :AccessLog => [] } - # opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging] - app_class = options[:app] ||= ::Middleman.server.inst opts[:app] = app_class - # Disable for Beta 1. See if people notice. + # Use Thin because Webrick gets confused and mixes + # up responses. + # TODO: Figure that out and drop Thin dependency require "thin" ::Thin::Logging.silent = !options[:logging] opts[:server] = 'thin' - # opts[:server] = 'webrick' server = ::Rack::Server.new(opts) server.start server end end -end \ No newline at end of file +end diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 7832435a..0c6b3296 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -88,6 +88,7 @@ module Middleman::Sitemap def render(opts={}, locs={}, &block) return File.open(source_file).read unless template? + start_time = Time.now puts "== Render Start: #{source_file}" if app.logging? md = metadata.dup @@ -106,7 +107,7 @@ module Middleman::Sitemap app.instance_eval(&block) if block_given? result = app.render_template(source_file, locs, opts) - puts "== Render End: #{source_file}" if app.logging? + puts "== Render End: #{source_file} (#{(Time.now - start_time).round(2)}s)" if app.logging? result end