Any tool to annotate the method so that the method doesn't generate logs
I have JUnit tests. In tests, I am testing cases where it goes into exception blocks in a test method. And they log errors that end up in my junit test results. I can do slf4j config and omit the whole class from the log. But I desire something where I can just comment out the test method and that ever executed code will not generate any logs.
+3
source to share
1 answer
(a) You can use two registrars, the default for the class and one method for your method:
private static final Logger log = LoggerFactory.getLogger(YourService.class);
private static final Logger customLog = LoggerFactory.getLogger(YourService.class.getCanonicalName() + "#yourMethod");
(b) Or, you can customize your logging system only in the setUp / tearDown test:
@SetUp
public void setUp() {
Logger log = LoggerFactory.getLogger(YourService.class);
((LoggerImlpementationClass) log).setLogLevel(...);
}
// the same, but reset, in tear down method.
However, in this case, you will need to change the scope of the log's dependency on runtime for validation (in maven conditions).
0
source to share