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 S.
Pawel S. wrote:
Regards
Pawel S.
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.
Hi Pawel,
Pawel S. 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
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 S.
On 22 Jun 2007, at 15:19, Pawel S. 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
ip_addr = request.env[âREMOTE_ADDRâ]
also:
request.remote_ip
Lots of good info available here:
http://api.rubyonrails.com/classes/ActionController/AbstractRequest.html
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 J. [email protected] wrote:
Peak Obsession
â
Robert W. Oliver II
CEO of OCS Solutions, Inc., Web Hosting and Development
Oops ⌠sorry about the space, should be:
ip_addr = request.env[âX_FORWARDED_FORâ]
Robert
On 6/24/07, Robert O. [email protected] wrote:
ip_addr = request.env [âX_FORWARDED_FORâ]
Robert
â
Robert W. Oliver II
CEO of OCS Solutions, Inc., Web Hosting and Development
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 S.
Robert O. 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. 
Nice, I wasnât aware of that. Thanks!
Robert
On 6/24/07, Carl J. [email protected] 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
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?
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