From 80c2a910e268532d42511d580c695a7b281054df Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 14 Dec 2020 16:15:20 -0600 Subject: [PATCH] SONAR-12786 Improve startup error message when the TCP port is already taken --- .../src/main/java/org/sonar/server/app/EmbeddedTomcat.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java b/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java index d0b0d4f74d0..e7bdc1d237f 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java @@ -19,12 +19,15 @@ */ package org.sonar.server.app; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; import com.google.common.base.Throwables; import java.io.File; import java.util.concurrent.CountDownLatch; import org.apache.catalina.LifecycleException; import org.apache.catalina.core.StandardContext; import org.apache.catalina.startup.Tomcat; +import org.slf4j.LoggerFactory; import org.sonar.api.utils.log.Loggers; import org.sonar.process.Props; @@ -63,7 +66,11 @@ class EmbeddedTomcat { TomcatConnectors.configure(tomcat, props); webappContext = new TomcatContexts().configure(tomcat, props); try { + // let Tomcat temporarily log errors at start up - for example, port in use + Logger logger = (Logger) LoggerFactory.getLogger("org.apache.catalina.core.StandardService"); + logger.setLevel(Level.ERROR); tomcat.start(); + logger.setLevel(Level.OFF); new TomcatStartupLogs(Loggers.get(getClass())).log(tomcat); } catch (LifecycleException e) { Loggers.get(EmbeddedTomcat.class).error("Fail to start web server", e); -- 2.39.5