Is it possible to get the full URLs in the logs of a Rails application? Currently I'm getting something like:
Started GET "/" for 127.0.0.1 at 2011-08-27 13:13:10 +0200
but I need to get:
Started GET "http://localhost:3000/" for 127.0.0.1 at 2011-08-27 13:13:10 +0200
because this is an app where the domains are important.
The line is coming from the middleware Rails::Rack::Logger
, which is in railties. At the simplest, you could just override the method doing the logging, e.g., in an initializer:
class Rails::Rack::Logger < ActiveSupport::LogSubscriber
protected
def before_dispatch(env)
request = ActionDispatch::Request.new(env)
info "\n\nStarted #{request.request_method} \"#{request.url}\" for #{request.ip} at #{Time.now.to_default_s}"
end
end
If you'd rather not override the logger, you could always add your own, which you've already created, then delete Rails::Rack::Logger
from the stack via:
config.middleware.insert_before(Rails::Rack::Logger, YourLogger)
config.middleware.delete(Rails::Rack::Logger)
If you go this route you might check out the rack logger for its usage of ActionDispatch::Request
, and be sure to do the other job it does of flushing the log subscriber cache after dispatch, via ActiveSupport::LogSubscriber.flush_all!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With