Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log Rails errors into a separate log file?

Our production logs are long and contain a lot more than just errors. I'd like a second log file with just the errors/exceptions in.

Is this possible?

We're using rails 2.x

Thanks.

like image 770
Christopher Stott Avatar asked Mar 29 '11 15:03

Christopher Stott


1 Answers

For example, to log all ActiveRecord::Base errors in a file called log/exceptions.log

new_logger = Logger.new('log/exceptions.log')
new_logger.level = Logger::ERROR
new_logger.error('THIS IS A NEW EXCEPTION!')

ActiveRecord::Base.logger = new_logger

For controllers and view(because ActionView logger doesn't have it's own logger, so it depends on the ActionController logger):

ActionController::Base.logger = new_logger
like image 175
Mike Lewis Avatar answered Oct 13 '22 00:10

Mike Lewis