Re: In some cases, using lookups for threadcontext does not output logs.
| Newsgroups | gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <[email protected]> |
We have confirmed that this issue has been resolved in 2.17.0.
Thanks to the contributors.
On 2021/12/15 16:09, taketake wrote:
> Hi everyone.
>
> I was checking the operation of 2.16.0.
>
> There, I found a case where no logs were output when I specified
> lookups for ThreadContext.
>
> Here is the code I tested.
>
>
> [log4j2.xml]
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="off">
> <appenders>
> <Console name="main" target="SYSTEM_OUT">
> <PatternLayout pattern="%m - $${ctx:userid}%n" />
> </Console>
> </appenders>
> <Loggers>
> <Root level="INFO" additivity="false">
> <AppenderRef ref="main"/>
> </Root>
> </Loggers>
> </Configuration>
>
>
> [Java]
> import org.apache.log4j.LogManager;
> import org.apache.log4j.Logger;
> import org.apache.logging.log4j.ThreadContext;
>
> public class Test {
> public static void main(String[] args) {
> Logger logger = LogManager.getLogger(Test.class);
>
> ThreadContext.put("userid", "${java:version}");
> logger.warn("case1");
>
> ThreadContext.put("userid", "${java:xxx}");
> logger.warn("case2");
>
> ThreadContext.put("userid", "${ctx:userid}");
> logger.warn("case3");
>
> ThreadContext.put("userid", "${ctx:xxx}");
> logger.warn("case4");
> }
> }
>
>
> [stdout]
> case1 - Java version 11.0.3
> case4 - ${ctx:xxx}
>
>
> Look at stdout.
> There is no output for case2 and case3.
>
> I think this is a bug, but what do you guys think?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>