I am using the Routing Appender in Log4J2 to route to different log files.
The path is determined by a custom LookUp. The configuration and the lookup
are as follows.

*Log4j2.xml Routing appender*

<Routing name="Routing">
   <Routes pattern="$${path:key2}">
          <RollingFile name="ABC_LOGFILE"

             <PatternLayout pattern="[%d] %5p {%c} - %m%ex%n" />
                <SizeBasedTriggeringPolicy size="50 MB" />
             <DefaultRolloverStrategy max="100" />

*Custom Lookup*

@Plugin(name = "path", category = StrLookup.CATEGORY)
public class LogFilePathLookup implements StrLookup {
    private static String logFilePath = "abc";

    public String lookup(String key) {
        return null;

    public String lookup(LogEvent logEvent, String key) {
        return logFilePath;

     * Sets the log file path.
     * @param logFilePath log file path
    public static void setLogFilePath(String logFilePath) {
        LogFilePathLookup.logFilePath = logFilePath;

This works perfectly when I run on the IDE (Intellij IDEA) with the VM
options set as

and some program arguments. But when the same is run in the terminal as

java -Dlog4j.configurationFile=/path/to/log4j2.xml
-Dabc.home=/home/asma/abchome -jar *<program_arguments>*

the name of the log file getting created is ${path:key2}.log, meaning it is
not replaced by the lookup String value. What could be the reason for this?


Reply via email to