Full URLs in Rails logs

Hello,

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.

2011/8/27 J. Pablo F. [email protected]

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.

Assuming you can’t, could you configure the logger to log different
domains
to different files?

It is possible with monkey patching by creating an initializer like
this:

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

Would there be any interest in having something like this, configurable,
in
Rails? (I did patches for Rails that never managed to gather enough
popularity and were ignored, I’m not wasting my time again)

2011/8/28 J. Pablo F. [email protected]

Would there be any interest in having something like this, configurable, in
Rails? (I did patches for Rails that never managed to gather enough
popularity and were ignored, I’m not wasting my time again)

I wouldn’t know, seems like it could be a somewhat common use case. I
was
just tryin’ to help :wink:

In any case, I don’t know about making it a patch, but you could make it
into a plugin and stick it on github and rubyforge. You’d be able to use
it
from multiple apps easily, and if there is interest in it, people can
use
it and contribute and whatnot.

Off-topic, making code like that reusable and public is never a waste of
time, imo. Every once in a while I’ll get a thank-you or a feature
request
for some little util I wrote, pushed public, and forgot – and it’s
pretty
neat.

Yes, I make re-usable code all the time… I released many gems and I
have
lot’s of github repos. The part that was a waste of time was creating a
patch for Rails.

On Aug 28, 9:39am, J. Pablo F. [email protected] wrote:

It is possible with monkey patching by creating an initializer like this:

I’m not entirely sure what you’re trying to do, but there’s nothing
stopping you creating your own log subscriber, attaching it to the
relevant events and log whatever you want

Fred