log4j2 主要参数没有被名称选中

log4j2 main arguments does not get picked up by the names

我正在尝试使用特定模式编写 log4j2 日志:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout charset="UTF-8"
                pattern="%d{HH:mm:ss.SSS} ${main:-jobId} %-5.-5level %-25.-25c{1}%-25.-25method(%5.5line) - %msg%n" />
        </Console>
        <RollingFile name="LogFile" fileName="${sys:logFile}"
            filePattern="${sys:logFile}-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout charset="UTF-8"
                pattern="%d{yyy-MM-dd HH:mm:ss.SSS} ${main:-jobId} [%-30.-30t] %-5.-5level %-25.-25c{1}%-25.-25method(%5.5line) - %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="100 MB" />
            </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="LogFile" level="debug" />
            <AppenderRef ref="Console" level="info" />
        </Root>
    </Loggers>
</Configuration>

我正在传递一些参数 -o abc -d def -jobId 1234 -DlogFile /usr/lib/logpath.log 这适用于系统参数,但日志打印为:

15:33:34.889 jobId INFO  Test           main                     (   74) - -b
15:33:34.890 jobId INFO  Test           main                     (   74) - -o
15:33:34.890 jobId INFO  Test           main                     (   74) - account
15:33:34.890 jobId INFO  Test           main                     (   74) - document
15:33:34.890 jobId INFO  Test           main                     (   74) - -d
15:33:34.891 jobId INFO  Test           main                     (   74) - rest
15:33:34.891 jobId INFO  Test           main                     (   74) - -l
15:33:34.891 jobId INFO  Test           main                     (   74) - 100
15:33:34.891 jobId INFO  Test           main                     (   74) - -skipmd
15:33:34.891 jobId INFO  Test           main                     (   74) - -db
15:33:34.891 jobId INFO  Test           main                     (   74) - -jobId
15:33:34.891 jobId INFO  Test           main                     (   74) - 1234

main 中的代码开头为:

public static void main(String[] args) throws Exception
    {
        MainMapLookup.setMainArguments(args);
        for (String s : args)
            logger.info(s);
...
}

我试过使用基于索引的参数,它有效。但是,主要参数查找似乎不起作用。我在这里遗漏了什么吗?

也许是个题外话,在日志记录的主要参数上处理系统变量的合法用例是什么?

它不起作用的原因是 MainMapLookup 按名称和 StrSubstitutor 默认值定界符之间的格式存在冲突。

${main:-jobId} 被解析为 属性 mainjobId

这是此处报告的已知错误:https://issues.apache.org/jira/browse/LOG4J2-1013