Skip to content

Commit

Permalink
Ensure that LabKey's log4j2.xml file is used
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-adam committed Sep 18, 2024
1 parent 654a5f8 commit 09baf36
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
Expand All @@ -23,6 +25,14 @@ public LabKeySpringBootClassLoader()
public LabKeySpringBootClassLoader(ClassLoader parent)
{
super(parent);

// HACK: This ensures that the "embedded" URLs get added first, so our canonical log4j2.xml file is found even
// if dependencies include their own version. See Issue 51286.
if (parent instanceof URLClassLoader ucl)
{
Arrays.stream(ucl.getURLs())
.forEach(this::addURL);
}
}

@Override
Expand Down Expand Up @@ -50,7 +60,7 @@ public Enumeration<URL> getResources(String name) throws IOException
// Eventually we should shift to only configuring and loading SLF4J and Log4J via Spring Boot and not
// from inside the webapp.
if (name.equalsIgnoreCase("META-INF/services/org.apache.logging.log4j.util.PropertySource") ||
name.equalsIgnoreCase("META-INF/services/org.apache.logging.log4j.spi.Provider") ||
name.equalsIgnoreCase("META-INF/services/org.apache.logging.log4j.spi.Provider") ||
name.equalsIgnoreCase("META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"))
{
List<URL> urls = new ArrayList<>();
Expand Down

0 comments on commit 09baf36

Please sign in to comment.