Skip to content

Missing servlet context in web lookup when using composite configurationΒ #2351

@apimentasoto

Description

@apimentasoto

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.

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:

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.

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

No one assigned

    Labels

    enhancementAdditions or updates to features

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions