GUACAMOLE-2181: Ensure our custom logging factory is used.

This commit is contained in:
Michael Jumper committed 2025-12-12 10:42:28 -08:00
1 parent 10558b2682
commit 1457b186ff
3 files changed
+73

No files matched your search

@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.guacamole;
import java.util.Set;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.guacamole.log.GuacamoleLogbackServiceProvider;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.Reporter;
/**
* ServletContainerInitializer which forces the SLF4J service provider to be
* Guacamole's built-in logging system. This is necessary as Logback also
* includes an SLF4J service provider, and there is no guarantee which provider
* will be chosen by SLF4J in the case that multiple are present.
* <p>
* SLF4J uses a "slf4j.provider" system property to allow a specific provider
* to be chosen, which this initializer sets automatically.
*/
public class GuacamoleServletContainerInitializer implements ServletContainerInitializer {
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
// Ideally, we want to use Guacamole's built-in logging facility, but
// we shouldn't override the administrator if they have their own SLF4J
// provider that needs to be used instead (ie: for some log aggregation
// service)
if (System.getProperty(LoggerFactory.PROVIDER_PROPERTY_KEY) == null) {
System.setProperty(LoggerFactory.PROVIDER_PROPERTY_KEY,
GuacamoleLogbackServiceProvider.class.getCanonicalName());
// Avoid excessive verbosity from SLF4J unless the administrator
// has explicitly chosen SLF4J's verbosity level (the SLF4J provider
// class will otherwise be logged at startup, which is an internal
// detail and not typically needed)
if (System.getProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY) == null)
System.setProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY, "WARN");
}
}
}
@@ -0,0 +1 @@
org.apache.guacamole.GuacamoleServletContainerInitializer
@@ -28,6 +28,14 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Ensure that our own ServletContainerInitializer is used to initialize
logging, and that Logback does not potentially initialize SLF4J first (which
would prevent our custom logging from taking effect) -->
<context-param>
<param-name>logbackDisableServletContainerInitializer</param-name>
<param-value>true</param-value>
</context-param>
<!-- Request that the browser always revalidate its cached copy of index.html -->
<filter>
<filter-name>cacheRevalidationFilter</filter-name>