-3

I want to implement access log in the ruby layer of my application. I want to log like this for each request.

192.168.2.20 - - [28/Jul/2006:10:27:10 -0300] "GET /cgi-bin/try/ HTTP/1.0" 200 3395
127.0.0.1 - - [28/Jul/2006:10:22:04 -0300] "GET / HTTP/1.0" 200 2216

I want to create a different file for access log only like apache access log. We can log the request in the rails logger that is easily achievable but how can we create separate log file only for access log. I am using trinidad.

1 Answers1

0

Everything you need can be found in the response header and body. Add a global action to your ApplicationController with a before_ or around_ action like:

/application_controller.rb

around_filter :logging_traffic

  def logging_traffic 
    logger.info "USERAGENT: #{request.headers['HTTP_USER_AGENT']}"
    begin 
      yield 
    ensure 
      logger.info "response_status: #{response.status}"
    end 
  end 
bkunzi01
  • 4,504
  • 1
  • 18
  • 25