ppkarwasz commented on PR #1471:
URL: https://github.com/apache/logging-log4j2/pull/1471#issuecomment-1554867873

   > Imagine I have two `should_jump()` and `should_crawl()` tests in a single 
test class and they verify the behaviour of logging component `Foo`. Each test 
method ideally should have its own `LoggerContext`. Though once `static final 
Logger LOGGER` field of `Foo` is initialized, it will trigger a single 
`LoggerContext` creation. Second, will this of `should_jump()` or 
`should_crawl()`? (Assume I want to run these tests in parallel.) In a 
nutshell, I am not able to see how to detach `LoggerContext`s of two different 
test methods. Any ideas?
   
   This is the difference between our unit tests and those of our users:
    * our classes use `StatusLogger.getLogger()`,
    * client code use `LogManager.getLogger()`.
   
   So we can use multiple `LoggerContext`s[1], while our clients can **only use 
one**. Apart this formal difference we are in the same situation: there is no 
way to work with multiple status loggers in a single test run, that is why I 
wrote 
[`StatusLoggerExtension`](https://github.com/apache/logging-log4j2/blob/2.x/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerExtension.java).
   
   Basically it works by adding and removing `StatusListener`s which filter out 
all messages that come from other threads. When I wrote it, it seemed a nice 
idea, but today I would rather write a **single** `StatusListener` that stores 
its log events in the appropriate (thread-bound :-P) 
[`ExtensionContext.Store`](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.Store.html).
   
   Probably the solution to your problem is similar: you should extend 
`ListAppender` to store messages in per-test lists.
   
   [1] IMHO this is quite wasteful: if we want to test a component, let's test 
just the component and not the entire initialization and configuration process, 
including the DI.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to