I'm searching for a while now a way to log only 404 errors in another log file than the other errors.
Is there a way to do it with the ruby logger or with log4r, in that way that the logging only happens in the new created log file?
I'm searching for a while now a way to log only 404 errors in another log file than the other errors.
Is there a way to do it with the ruby logger or with log4r, in that way that the logging only happens in the new created log file?
On
Whilst I don't have a specific recommendation, I do have some experience with this type of thing. Maybe this will help...
--
I've written a gem called exception_handler which basically interjects into the exceptions_app middleware, allowing you to send any exceptions to a controller action.
One of the things you could do would be to use the technology in this gem to capture the 404 exceptions, and perform your own logging with them:
#config/application.rb
...
config.exceptions_app = ->(env) { ApplicationController.action(:exception).call(env) }
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def exception
@error_code = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
[[own logging]] if @status == 404
end
end
This would be a start; I don't know how you'd make your own log file etc, and also this is very constrictive in the sense that if the error is anything other than 404, it may time out.