I have the following code and I want to write any errors generated when running it to a log file.
How can I do that in rails?
def get_score
if status == "approved"
begin
metrics = Popularity.get_metrics(url,nil ,:resource)
update_column(:metrics, metrics.to_yaml)
update_column(:score,Popularity.score(metrics,:resource ))
reputation = reputations.build(:metrics => metrics)
reputation.score = score
reputation.save
rescue
#write the error that was raised to a log file
end
end
How about this
The
Rails.logger.debugwill log the error in thelog/[your environment].logwith a
debugtag alternatively you can also usedRails.logger.info "Opps Error Occurred -- > #{e} "