You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Stefano Rocca (JIRA)" <ji...@apache.org> on 2018/10/18 15:08:00 UTC

[jira] [Created] (LOG4J2-2480) WebLookup not working in log4jConfiguration parameter

Stefano Rocca created LOG4J2-2480:
-------------------------------------

             Summary: WebLookup not working in log4jConfiguration parameter
                 Key: LOG4J2-2480
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2480
             Project: Log4j 2
          Issue Type: Bug
          Components: Web/Servlet
    Affects Versions: 2.11.1
         Environment: We're using:

Windows 10

JDK 1.8.0_144

Tomcat 8.0.36

Log4j2 2.11.1
            Reporter: Stefano Rocca


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(); {color:#FF0000}<-- returns null!{color}}}
{{        if (ctx == null) {}}
{{             return null; {color:#FF0000}<-- exits{color}}}
{{        }}}

Thanks in advance.

Stefano



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)