Full URLs in Rails logs

10 views
Skip to first unread message

J. Pablo Fernández

unread,
Aug 27, 2011, 8:16:44 AM8/27/11
to rubyonra...@googlegroups.com
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.

Jeremiah Dodds

unread,
Aug 27, 2011, 6:46:47 PM8/27/11
to rubyonra...@googlegroups.com


2011/8/27 J. Pablo Fernández <pup...@pupeno.com>
Assuming you can't, could you configure the logger to log different domains to different files? 

J. Pablo Fernández

unread,
Aug 28, 2011, 4:39:18 AM8/28/11
to rubyonra...@googlegroups.com
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)

Jeremiah Dodds

unread,
Aug 28, 2011, 7:05:40 AM8/28/11
to rubyonra...@googlegroups.com


2011/8/28 J. Pablo Fernández <pup...@pupeno.com>
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 ;)

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.

J. Pablo Fernández

unread,
Aug 28, 2011, 9:00:34 AM8/28/11
to rubyonra...@googlegroups.com
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.

Frederick Cheung

unread,
Aug 28, 2011, 11:44:44 AM8/28/11
to Ruby on Rails: Talk


On Aug 28, 9:39 am, J. Pablo Fernández <pup...@pupeno.com> 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
Reply all
Reply to author
Forward
0 new messages