Provare quanto segue. Metti il metodo rescue_from nel tuo controller.
Non l'ho provato. Ma forse ti mette nella giusta direzione
class ApplicationController < ActionController::Base
rescue_from StandardError do |exception|
new_logger = Logger.new('log/exceptions.log')
new_logger.info('THIS IS A NEW EXCEPTION!')
new_logger.info(exception.message)
new_logger.info(exception.backtrace)
# Raise it anyway because you just want to put it in the log
raise exception
end
end
Se si utilizza Rails 2.1 (anche non testato)
class ApplicationController < ActionController::Base
def rescue_action_in_public(exception)
new_logger = Logger.new('log/exceptions.log')
new_logger.info('THIS IS A NEW EXCEPTION!')
new_logger.info(exception.message)
new_logger.info(exception.backtrace)
# Raise it anyway because you just want to put it in the log
raise exception
end
end
fonte
2011-03-29 16:24:42
possibile duplicato di [Come accedere qualcosa in Rails in un file di log indipendente?] (http://stackoverflow.com/questions/337739/how-to-log-something-in-rails-in-an-independent-log-file) – fl00r
Non penso che sia un duplicato - è una domanda diversa. Informazioni su come suddividere automaticamente i file di registro standard in parti più fini, anziché eseguire manualmente la registrazione in un file separato. –