From: simonbrandhof Date: Sun, 30 Oct 2011 20:50:34 +0000 (+0100) Subject: SONAR-2932 log exception stacktrace X-Git-Tag: 2.12~77 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c485bcc337ee4527f00e2313dcd0bd15ca82ccb;p=sonarqube.git SONAR-2932 log exception stacktrace --- diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 7e01bb368d2..0b80ed0cb5e 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -369,6 +369,10 @@ public final class JRubyFacade { return i18n.getJsDictionnary(rubyLocale); } + public void logError(String message) { + LoggerFactory.getLogger(getClass()).error(message); + } + public ReviewsNotificationManager getReviewsNotificationManager() { return getContainer().getComponentByType(ReviewsNotificationManager.class); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb index 5deb4851b67..c799f91a95b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb @@ -138,7 +138,9 @@ class ApplicationController < ActionController::Base end def render_error(error) - logger.error("Fail to render: #{request.url}", error) + # Ruby on Rails has a single logger "rails", so it's not possible to distinguish profiling logs + # from error logs. For this reason a standard SLF4J logger is used instead of logger.error(). + java_facade.logError("Fail to render: #{request.url}\n#{Api::Utils.exception_message(error)}") render :file => "#{Rails.public_path}/500.html", :status => 500 end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index 9e213019a6c..87ca9d86715 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -66,4 +66,12 @@ class Api::Utils params = options[:params]||[] Java::OrgSonarServerUi::JRubyFacade.getInstance().getMessage(I18n.locale, key, default, params.to_java) end + + def self.exception_message(exception) + result = (exception.respond_to?(:message) ? "#{exception.message}\n" : "#{message}\n") + if exception.respond_to? :backtrace + result << "\t" + exception.backtrace.join("\n\t") + "\n" + end + result + end end