-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
Web lookup doest not work when configuring a web application using a list of configuration files.
While using the log4j-web module and setting log4jConfiguration as a list of files the web initializer calls Configurator.initialize passing a Map.Entry<String, Object> as the last argument.
logging-log4j2/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
Lines 171 to 183 in 32075af
if (location != null && location.contains(",")) { | |
final List<URI> uris = getConfigURIs(location); | |
this.loggerContext = Configurator.initialize( | |
this.name, | |
this.getClassLoader(), | |
uris, | |
WebLoggerContextUtils.createExternalEntry(this.servletContext)); | |
return; | |
} | |
final URI uri = getConfigURI(location); | |
this.loggerContext = Configurator.initialize( | |
this.name, this.getClassLoader(), uri, WebLoggerContextUtils.createExternalEntry(this.servletContext)); |
The configurator does not implement a method which accepts a list of locations and an entry (as it does for the case of a single location) and instead matches this method:
logging-log4j2/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
Lines 184 to 188 in 32075af
public static LoggerContext initialize( | |
final String name, | |
final ClassLoader loader, | |
final List<URI> configLocations, | |
final Object externalContext) { |
Which in turn calls this which does not correctly set the context.
logging-log4j2/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
Lines 290 to 301 in 32075af
public LoggerContext getContext( | |
final String fqcn, | |
final ClassLoader loader, | |
final Object externalContext, | |
final boolean currentContext, | |
final List<URI> configLocations, | |
final String name) { | |
final LoggerContext ctx = | |
selector.getContext(fqcn, loader, currentContext, null /*this probably needs to change*/); | |
if (externalContext != null && ctx.getExternalContext() == null) { | |
ctx.setExternalContext(externalContext); | |
} |
Configuration
Version: 2.3.0
Operating system: windows 11
JDK: JDK 17
Reproduction
- Add log4j-web module to web applciation.
- Set the init param log4jConfiguration as a list of properties (
<Parameter name="log4jConfiguration" value="log4j2-foo.properties,log4j2-bar.properties"/>
) - Lookup the servletContextName or any other ServletContxt variable in one of the properties files (${web:servletContextName})
Metadata
Metadata
Assignees
Labels
Type
Projects
Status