Property substitution doesn't work in log4j2 xml config

Alex Orlov <[email protected]> Mon, 30 Oct 2023 17:25:19 +0300
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
Hi all,
 
I use log4j 2.21.1. This is my xml config file:
 
    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="debug">
        <Appenders>
            <File name="File" fileName="./../log/log-${sys:foo.test}.txt" immediateFlush="true" append="false">
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{[%level]}{FATAL=bright_red bold, ERROR=red bold, WARN=yellow bold, INFO=blue bold, DEBUG=green bold, TRACE=magenta bold} [%t] %logger{36} - %msg%n" disableAnsi="false"/>
            </File>
        </Appenders>
    
        <Loggers>
            <Root level="debug">
                <AppenderRef ref="File"/>
            </Root>
        </Loggers>
    </Configuration>
 
This is a piece of my MainClass:
 
    public final class MainClass {
    
        static {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hhmmss");
            System.setProperty("foo.test", dateFormat.format(new Date()));
        }
    
        .....
    }
 
However, the generated log file is `log-${sys:foo.test}.txt`. I mean:
 
    user@pc:~/Temp/log$ ls
    'log-${sys:foo.test}.txt'
 
According to docs https://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution my solution must work but it doesn't. Could anyone say how to fix it?
 
 
--
Best regards, Alex Orlov