Include params/request information in Rails logger?

前端 未结 3 1338
失恋的感觉
失恋的感觉 2020-12-24 08:51

I\'m trying to get some more information into my Rails logs, specifically the requested URI or current params, if available (and I appreciate that they won\'t always be). Ho

3条回答
  •  醉话见心
    2020-12-24 08:59

    This should work! :) cheers.

    logger.info({:user_agent => request.user_agent, :remote_ip => request.remote_ip}.inspect)

    logger.info(params.inspect)

    By the by.. This should be placed in your controllers action. Ex: If you place it in your create action it should also log the user_agent i.e the browser, remote_ip i.e the remote ip of the user and all the params.

提交回复
热议问题