config/routes.rbの末尾に以下を追加。
config/routes.rb
# Not Foundのときログにスタックトレースを残さないようにするため
# https://stackoverflow.com/a/39289253/5209556
match '*any' => 'pages#not_found', via: [:get, :post]
app/controllers/pages_controller.rb
class PagesController < ApplicationController
layout false
# Not Foundだけ別ファイルにログを出す
NotFoundLogger = Logger.new(Rails.root.join("log/not_found.log"))
# Not Foundのときログにスタックトレースを残さないようにするため
# https://stackoverflow.com/a/39289253/5209556
def not_found
NotFoundLogger.error(request.fullpath)
render file: 'public/404.html', status: :not_found, layout: nil
end