Permalink
Browse files

added logging, so that you know when Publicious served a request, and…

… what it served
  • Loading branch information...
1 parent 8df9715 commit 3cb3b07f089a26115fcac87c0900702ea4a8edeb @justinfrench committed Jul 23, 2010
Showing with 12 additions and 1 deletion.
  1. +9 −1 lib/publicious.rb
  2. +1 −0 lib/publicious/railtie.rb
  3. +2 −0 test/test_helper.rb
View
@@ -3,8 +3,14 @@
require 'publicious/mime_types'
end
+require 'logger'
+
class Publicious
FILE_METHODS = %w(GET HEAD).freeze
+
+ @@logger = Logger.new($stdout)
+ @@logger.level = Logger::DEBUG
+ cattr_accessor :logger
def initialize(app)
@app = app
@@ -16,6 +22,7 @@ def klass
end
def call(env)
+
request = Rack::Request.new(env)
return @app.call(env) unless FILE_METHODS.include?(request.request_method)
@@ -33,7 +40,8 @@ def call(env)
# Make sure pricks aren't ../../config/database.yml ing us
respond_not_found! unless file_name.gsub(%r[^#{path}], "") == request.path_info
-
+
+ klass.logger.info "Publicious middleware served #{request.path_info} with #{file_name}"
Rack::Response.new(
File.open(file_name),
200,'Content-Type' => content_type_for_file(file_name)
@@ -1,5 +1,6 @@
class MyRailtie < Rails::Railtie
initializer "publicious.configure_middleware" do |app|
app.middleware.insert_before(Rack::Lock, Publicious)
+ Publicious.logger = Rails.logger
end
end
View
@@ -5,6 +5,8 @@
require "action_controller"
require "publicious"
+Publicious.logger.level = Logger::ERROR # Silence INFO logs from the middleware during tests
+
RAILS_ROOT = "/tmp"
NOT_FOUND_APP = lambda{|e| Rack::Response.new("NOT FOUND", 404).finish}

0 comments on commit 3cb3b07

Please sign in to comment.