[ 
https://issues.apache.org/jira/browse/LOG4J2-2480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stefano Rocca updated LOG4J2-2480:
----------------------------------
    Environment: 
Windows 10

JDK 1.8.0_144

Tomcat 8.0.36

Log4j2 2.11.1

  was:
We're using:

Windows 10

JDK 1.8.0_144

Tomcat 8.0.36

Log4j2 2.11.1

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



Thanks in advance.

Stefano

  was:
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


> 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: Windows 10
> JDK 1.8.0_144
> Tomcat 8.0.36
> Log4j2 2.11.1
>            Reporter: Stefano Rocca
>            Priority: Minor
>
> 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)

Reply via email to