diff --git a/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java b/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java index afdbb6785..1eea13c7c 100644 --- a/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java +++ b/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java @@ -19,11 +19,17 @@ package org.apache.guacamole; +import ch.qos.logback.core.joran.spi.JoranException; +import java.io.IOException; +import java.io.InputStream; import java.util.Set; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.apache.guacamole.log.GuacamoleLogbackServiceProvider; +import org.apache.guacamole.log.LogLevel; +import org.apache.guacamole.log.ReconfigurableLoggerFactory; +import org.slf4j.ILoggerFactory; import org.slf4j.LoggerFactory; import org.slf4j.helpers.Reporter; @@ -38,6 +44,12 @@ import org.slf4j.helpers.Reporter; */ public class GuacamoleServletContainerInitializer implements ServletContainerInitializer { + /** + * The log level that should be used when we have not yet loaded any + * configuration dictating otherwise. + */ + private static final LogLevel EARLY_LOG_LEVEL = LogLevel.INFO; + @Override public void onStartup(Set> c, ServletContext ctx) throws ServletException { @@ -59,6 +71,20 @@ public class GuacamoleServletContainerInitializer implements ServletContainerIni } + // Attempt early initialization of Logback (before we begin parsing + // Guacamole's configuration), such that even startup messages follow + // a consistent format + try (InputStream logbackConfiguration = EARLY_LOG_LEVEL.getLogbackConfiguration()) { + ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); + if (loggerFactory instanceof ReconfigurableLoggerFactory) + ((ReconfigurableLoggerFactory) loggerFactory).reconfigure(logbackConfiguration); + } + catch (JoranException | IOException e) { + System.err.println("Early initialization of Logback failed - " + + "logging format may not match until the web application " + + "finishes starting up: " + e.getMessage()); + } + } }