Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that LabKey's log4j2.xml file is used #883

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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