I’m currently using Rails v2.3.5 at work and I’m quite new both to the language and the framework. What I need to do is to capture certain information every time a user requests a webpage (user’s IP address, URL accessed, Date and time of access and the time the page took to render) and store it in a database.
I’ve noticed that all this information is contained in the default Rails’ logfiles, but I’m trying to avoid having to parse the logfile to collect this information. What I would like is some way to hook to the logger and intercept this information or perhaps extend the logger and use my extended version instead of the default Rails one (ActiveSupport::BufferedLogger).
Maybe ever other solutions that don’t require logs?
Thanks in advance.
What you probably need is a
before_filterblock in your ApplicationController to perform whatever action you need to do. From there you can create whatever database records you need. For example:Hooking in to the logger is probably a bad idea as that’s an indirect way to get that information. You may need to extract data from this for historical reasons, though.