How to disable Rails RoutingError stacktrace printout in Production log files?

前端 未结 2 1664
长发绾君心
长发绾君心 2021-02-13 05:15

In my proudction rails app, I got all types of random attacks requesting for asp, zip and rar files. Rails rendered 404 page as expected, but my production log file is jammed wi

2条回答
  •  醉话见心
    2021-02-13 05:36

    Rails 4 and 5 answer:

    match '*any', to: 'not_found#anything', via: [:get, :post]
    

    To match a wildcard parameter, it must have a name assigned to it - any in this case.

    class NotFoundController < ApplicationController
      def anything
        Logger.new('log/not_found.log').info(request.fullpath)
        # To render nothing:
        # head :not_found #Rails 5
        # render nothing: true, status: :not_found # for Rails 4
    
        #To render 404 page
        render file: 'public/404.html', status: :not_found, layout: false
      end
    end
    

提交回复
热议问题