[
https://issues.apache.org/jira/browse/LOG4J2-962?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14654938#comment-14654938
]
Romuald Fleury commented on LOG4J2-962:
---------------------------------------
Thanks for your responses.
You can reproduce the problem very easily with the following:
{code:java}
@Test
public void testLog4j2() throws Exception
{
MapLookup.setMainArguments(new String[]{"main-arg"});
LOG.info("INFO MESSAGE");
LOG.warn("INFO MESSAGE");
LOG.error("INFO MESSAGE");
}
{code}
{code:xml}
...
<File name="MainSys" fileName="app-${main:0}.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
...
<AppenderRef ref="MainSys" />
...
{code}
{code:xml}
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.2</version>
</dependency>
{code}
> Main Arguments Lookup not working
> ---------------------------------
>
> Key: LOG4J2-962
> URL: https://issues.apache.org/jira/browse/LOG4J2-962
> Project: Log4j 2
> Issue Type: Bug
> Components: Lookups
> Affects Versions: 2.1
> Environment: Windows 7 x64, Java Batch Application
> Reporter: Johannes Siebel
>
> It is not possible to use the Main Arguments Lookup in the current version.
> The "main" prefix is not present in the corresponding Interpolator object and
> thus the resolution of the variable is not working as advertised in the
> documentation, e.g. using the following variable in the log4j2.xml:
> {code}${main:0}{code}
> As far as I can tell, the problem seems to stem from the
> PluginManger.collectPlugins-Method that does not acknowledge the existence of
> the Main Arguments Lookup.
> I'm following the documentation on the website with the following sample
> log4j2.xml:
> {code:xml}
> <File name="GLOBAL" fileName="${env:DATA_DIR}/log/${env:APP_NAME}.log" >
> <PatternLayout pattern="%m%n" header="File: ${main:0}" />
> ...
> {code}
> ...and following code in my application:
> {code}
> public static void main(String[] args) {
> MapLookup.setMainArguments(args);
> ...
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]