Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.11.1
-
None
-
None
-
Windows 10
JDK 1.8.0_144
Tomcat 8.0.36
Log4j2 2.11.1
Description
Hi,
we'd like to use a servlet init parameter inside the log4jConfiguration parameter like this (web.xml):
<context-param>
<description>Log4j config location</description>
<param-name>log4jConfiguration</param-name>
<param-value>${web:initParam.config.folder}/log4j2_ui.xml</param-value>
</context-param>
where config.folder is a servlet init parameter (defined in context.xml).
Looking at org.apache.logging.log4j.web.Log4jWebInitializerImpl we have seen at line 104 that it is possible to use variable substitution inside log4jConfiguration
final String location = this.substitutor.replace(this.servletContext
.getInitParameter(LOG4J_CONFIG_LOCATION));
but in our case it does not work: we see that it recognizes the variable and it tries to lookup the value in the servlet context but in the following method of org.apache.logging.log4j.web.WebLookup, at line 35 ctx is null
public String lookup(final LogEvent event, final String key) {
final ServletContext ctx = WebLoggerContextUtils.getServletContext(); <-- returns null!
if (ctx == null) {
return null; <-- exits
Thanks in advance.
Stefano