views:

55

answers:

2

Hi,

I have a Rails application but after some time of development/debugging I realized that it would be very helpful to be able to see the whole HTTP request in the logfiles - log/development.log, not just the parameters.

I also want to have a separate logfile based on user, not session.

Any ideas will be appreciated!

Angel

+4  A: 

You can rapidly see the request.env in a view via:

  • VIEW: <%= request.env.inspect %>

If instead you want to log it in development log, from your controller:

  • CONTROLLER: Rails.logger.info(request.env)

Here you can see a reference for the Request object.

Rails automatically sets up logging to a file in the log/ directory using Logger from the Ruby Standard Library. The logfile will be named corresponding to your environment, e.g. log/development.log.

To log a message from either a controller or a model, access the Rails logger instance with the logger method:

class YourController < ActionController::Base
  def index
    logger.info request.env
  end
end

About the user, what are you using to authenticate It?

microspino
Hi,thank you for the reply, it really helps. I am using authlogic for authentication.
akafazov
...then logger.info current_user.inspect would be your friend ;) .
microspino
A: 

You can use rack middleware to log the requests as the middleware sees them (as parsed by the http-server and as transformed by preceding middleware). You can also configure your http-server to log full requests, if your http-server supports such a feature.

The http-server (web-server) is responsible for receiving http requests, parsing them, and transmitting data structures to the application-server (e.g., a rack application). The application-server does not see the original request, but sees what the http-server sends its way.

Justice
Thank a log, great tip.
akafazov