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

Konstantinos Liakos commented on LOG4J2-3258:
---------------------------------------------

Hi [~rgoers] , please find below the full XML configuration for my use case.

 

${logs_dir} is resolved as ${env:LOGS_DIRECTORY} instead of the actual 
environment variable value.

 

 
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <Property name="logs_dir">$${env:LOGS_DIRECTORY}</Property>
    </Properties>
    <Appenders>
        <Routing name="Routing">
            <Routes pattern="$${ctx:logFile}">
                <!-- This route is chosen if ThreadContext has no value for key 
logFile. -->
                <Route key="$${ctx:logFile}">
                    <RollingFile name="Rolling-application" 
fileName="${logs_dir}/application.log" 
filePattern="${logs_dir}/${date:yyyy-MM}/default-%d{yyyy-MM-dd}-%i.log.gz">
                        <JSONLayout compact="true" eventEol="true" 
includeTimeMillis="true"/>
                        <Policies>
                            <SizeBasedTriggeringPolicy size="10 MB"/>
                        </Policies>
                    </RollingFile>
                </Route>
                 <!-- This route is chosen if ThreadContext has a value for 
logFile. The value dynamically determines the name of the log file. -->
                <Route>
                    <RollingFile name="Rolling-${ctx:logFile}" 
fileName="${logs_dir}/${ctx:logFile}.log" 
filePattern="${logs_dir}/${date:yyyy-MM}/${ctx:logFile}-%d{yyyy-MM-dd}-%i.log.gz">
                        <JSONLayout compact="true" eventEol="true" 
includeTimeMillis="true"/>
                        <Policies>
                            <SizeBasedTriggeringPolicy size="10 MB"/>
                        </Policies>
                    </RollingFile>
                </Route>
            </Routes>
        </Routing>
    </Appenders>
    <Loggers>
        <Root level="${env:LOG_LEVEL:-ALL}">
            <AppenderRef ref="Routing"/>
        </Root>
    </Loggers>
</Configuration>{code}
 

 

> 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.
>  
> {code:java}
> <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