[ 
https://issues.apache.org/jira/browse/LOG4J2-3258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17462999#comment-17462999
 ] 

Ralph Goers commented on LOG4J2-3258:
-------------------------------------

Looking at this      

{code:java}
<Property name="logs_dir">$${env:LOGS_DIRECTORY}</Property>
{code}

doesn't seem correct to me.  Environment variables can't change while a Java 
application is running. So this should really be:

{code:java}
<Property name="logs_dir">${env:LOGS_DIRECTORY}</Property>
{code}

which will cause the value to be resolved when the configuration is processed.

The change made in Log4j 2.17.0 is that recursive lookups are allowed in the 
configuration on anything that is not evaluated in connection with a log event. 
In your case I would have expected that the fileName would continue to work 
since that is only evaluated when the RollingFileManager is created. But the 
filePattern is evaluated on every rollover so will no longer be allowed to have 
recursive lookups.

As I expected you are using the Routing appender. While that will continue to 
work you need to make sure the value of logFile cannot be derived from anything 
coming from outside the application, such as user input or an http header.


> RollingFile fileName containing variables does not work on 2.17.0
> -----------------------------------------------------------------
>
>                 Key: LOG4J2-3258
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3258
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.17.0
>         Environment: Java 17, Ubuntu 20.04.
>            Reporter: Konstantinos Liakos
>            Priority: Major
>
> A configuration like the below has stopped working since 2.17.0. The 
> variables that originate from <Properties> are not resolved to their actual 
> values.
> {code:xml}
> <Property name="logs_dir">$${env:LOGS_DIRECTORY}</Property> {code}
> {code:xml}
> <RollingFile name="Rolling-${ctx:logFile}" 
> fileName="${logs_dir}/${ctx:logFile}"{code}
>  
> Works fine on 2.16.0.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to