[
https://issues.apache.org/jira/browse/LOG4J2-786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14101697#comment-14101697
]
Matt Sicker commented on LOG4J2-786:
------------------------------------
I added a functional version of the above test in r1618779 (trunk). Take a look
at {{org.apache.logging.log4j.core.lookup.ContextMapLookupTest}} in
{{log4j-core}}. You won't need to use the {{InitialLoggerContext}} rule since
this just sets up a new configuration based on the given file name. If you use
a static file, then there's no need for the additional rule. That rule is
primarily useful because we have dozens of config files in the tests. The main
idea here is the config file:
{code}
<Configuration status="error" name="ContextMapLookupTest">
<Appenders>
<File name="File"
fileName="target/${ctx:testClassName}.${ctx:testMethodName}.log">
<PatternLayout pattern="%m%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
{code}
Before I obtain a Logger from LogManager, I use
{{ThreadContext.put("testClassName", "foo")}} etc. That way when the Logger is
obtained and the configuration file is parsed, it uses the current MDC. Using a
TestRule just makes this a lot easier to integrate with unit tests.
> Unit testing with log4j2
> -------------------------
>
> Key: LOG4J2-786
> URL: https://issues.apache.org/jira/browse/LOG4J2-786
> Project: Log4j 2
> Issue Type: Improvement
> Reporter: Alex Newman
> Priority: Critical
>
> I still have no idea, how with a maven project with submodules, how to create
> a separate file per test with the test output in it. I used to just output to
> the console and then use maven.test.redirectTestOutput. This no longer works.
> It was nice to be able to just turn this on and off with a simple property.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]