Hello, I want to log users who enter my site and what they are doing. Registration and login is not required, so what is left is IP. (something like wikipedia, you can edit without logging in, and then there is your IP in log). How to get this IP in Ruby on Rails? And if you know some nice tutorial about logging in ruby I would also appreciate ;) I mean logging events to some file, not logging users to service :) Regards Pawel Stawicki -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pawel Stawicki wrote:> Hello, > > I want to log users who enter my site and what they are doing. > Registration and login is not required, so what is left is IP. > (something like wikipedia, you can edit without logging in, and then > there is your IP in log). How to get this IP in Ruby on Rails? > > And if you know some nice tutorial about logging in ruby I would also > appreciate ;) I mean logging events to some file, not logging users to > service :) > > Regards > Pawel Stawicki >A google search for this ''rails ip address of client'' returned this: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/238784 which gave this: ip_addr = request.env[''REMOTE_ADDR''] Sorry, can''t answer the second question :) Cheers, Mohit. 6/22/2007 | 7:53 PM. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Pawel, Pawel Stawicki wrote:> I want to log users who enter my site and what they are doing. > Registration and login is not required, so what is left is IP. > (something like wikipedia, you can edit without logging in, and then > there is your IP in log). How to get this IP in Ruby on Rails? > > And if you know some nice tutorial about logging in ruby I would also > appreciate ;) I mean logging events to some file, not logging users to > service :)Rails is probably already logging everything you''re looking for in #{RAILS_ROOT}/log/production.log. Every request/reponse cycle generates an entry containing the time of the request, the requesting IP address, the session id, controller / action requested, parameters passed, and response. You might want to consider using the session id rather than IP address to track visitors. If the visitor is using AOL, for example, the IP address you see can change during their visit. I haven''t tested it, but I think Rails will maintain the same session ID throughout. If you''re in development mode, your development.log will contain more info than your production.log will when you switch to that environment. If you want to see what you''ll be getting when you move to production, just uncomment the line (around line 27) in #{RAILS_ROOT}/config/environment.rb that reads "#config.log_level = :debug" and change it to "config.log_level = :info". Hope that helps, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for all the answers. I think I will use some logging because I want to log what user does in my application. This can be all retrieved from actions and parameters data, but I prefer to have it logged in more human-readable way. I know IP is not perfect, but without user login it is the best I can have. Regards Pawel Stawicki -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Jun 2007, at 15:19, Pawel Stawicki wrote:> I think I will use some logging because I want to log what user > does in > my application. This can be all retrieved from actions and parameters > data, but I prefer to have it logged in more human-readable way. I > know > IP is not perfect, but without user login it is the best I can have.You''ll be better of writing a log analyzer (and visualizer) than a method call and another hit on your db on each request. The logs aren''t that difficult to parse and you can parse the whole lot during the night and generate staticly cached pages. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> You''ll be better of writing a log analyzer (and visualizer) than a > method call and another hit on your db on each request. The logs > aren''t that difficult to parse and you can parse the whole lot during > the night and generate staticly cached pages.Why DB? I want to log to file only. Thanks anyway. Regards Pawel Stawicki -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> ip_addr = request.env[''REMOTE_ADDR'']also: request.remote_ip Lots of good info available here: http://api.rubyonrails.com/classes/ActionController/AbstractRequest.html -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just want to mention also that if you are behind a load balancer, the REMOTE_ADDR may return the load balancer''s IP, not the actual client''s. In this case, you can typically use something like: ip_addr = request.env[''X_FORWARDED_FOR''] Robert On 6/24/07, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > ip_addr = request.env[''REMOTE_ADDR''] > > also: > > request.remote_ip > > Lots of good info available here: > > http://api.rubyonrails.com/classes/ActionController/AbstractRequest.html >-- Robert W. Oliver II CEO of OCS Solutions, Inc., Web Hosting and Development http://www.ocssolutions.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oops .. sorry about the space, should be: ip_addr = request.env[''X_FORWARDED_FOR''] Robert On 6/24/07, Robert Oliver <rwoliver2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > ip_addr = request.env [''X_FORWARDED_FOR''] > > Robert > > >-- Robert W. Oliver II CEO of OCS Solutions, Inc., Web Hosting and Development http://www.ocssolutions.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Oliver wrote:> Just want to mention also that if you are behind a load balancer, the > REMOTE_ADDR may return the load balancer''s IP, not the actual client''s.That''s why I recommended request.remote_ip. It returns HTTP_CLIENT_IP or X_FORWARDED_FOR if present, otherwise REMOTE_IP. No need for you to repeat what Rails already does for you. :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nice, I wasn''t aware of that. Thanks! Robert On 6/24/07, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > That''s why I recommended request.remote_ip. It returns HTTP_CLIENT_IP or > X_FORWARDED_FOR if present, otherwise REMOTE_IP. No need for you to > repeat what Rails already does for you. :) > >-- Robert W. Oliver II CEO of OCS Solutions, Inc., Web Hosting and Development http://www.ocssolutions.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Im using request.remote_ip now but the problem is if im behind a proxy i always get ip as 127.0.0.1 But in the development.log i can see the correct ip like this Processing AuthController#login (for 192.168.1.4 at 2007-07-05 11:31:17) [POST] Is there a way to get the ip from the log or some other workaround? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Im using request.remote_ip now but the problem is if im behind a proxy i > always get ip as 127.0.0.1 > > But in the development.log i can see the correct ip like this > Processing AuthController#login (for 192.168.1.4 at 2007-07-05 11:31:17) > [POST] > > Is there a way to get the ip from the log or some other workaround?Spit out the contents of request.env (a hash) and see if what you want is in there. Usually there''s an X-header that will have the clients ip... -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---