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.
As of Rails 3.2.12, instead of monkey-patching before_dispatch or call_app, there is now a method that receives the request and returns the
Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
bit.So you can instead override that method in your own logger or monkey patch just that method.
If you subclass don't forget to modify the middleware chain in
config/application.rb
(and make sure URLLogger is loaded before the configuration block):I don't think you can do this without changing Rails itself, which isn't nice, but you can add your own log call:
A workaround I'm using for now was creating this class:
and then adding it as Rack middleware (in application.rb):
so I get:
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: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: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, viaActiveSupport::LogSubscriber.flush_all!