[ 
https://issues.apache.org/jira/browse/LOG4J2-3083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17392332#comment-17392332
 ] 

Carter Kozak commented on LOG4J2-3083:
--------------------------------------

I don't see any direct testing of the slf4j caller lookup implementation, this 
makes sense because I believe it's currently broken. It's particularly 
difficult to test because we map from caller location to a class, to a 
classloader which is used to locate the logger context, so it's hard to 
validate across so many layers of indirection.

I've got a work-in-progress test which leverages trace-level status-logger 
logging of the detected caller class to verify our expectations. Unfortunately 
this doesn't work with all tests yet because the slf4j-impl module tests also 
depend on log4j-to-slf4j for OverflowTest (expecting LoggerFactory.getLogger to 
throw an exception when log4j-to-slf4j is present).

The second problem is that it's difficult to test all codepaths -- I don't 
think our tests validate code in the java9 modules unless that code is 
explicitly tested. multi-release jars are difficult to test, and I've only 
managed to make multirelease jar testing work using gradle since that's what we 
use at work, although that mr-jar setup isn't particularly maintainable or easy 
to work with.

> Why the logger get by Slf4j LoggerFactory.getILoggerFactory() can only use 
> current LoggerContext
> ------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3083
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3083
>             Project: Log4j 2
>          Issue Type: Question
>    Affects Versions: 2.13.3
>         Environment: Spring Boot 2.4.5
> Slf4j
>            Reporter: wanghao
>            Assignee: Ralph Goers
>            Priority: Major
>              Labels: newbie
>
> In SpringBoot project with +test+ profile,
> org.slf4j.LoggerFactory.getLogger("xxx") can get test profile LoggerContext 
> and read configuration from log4j2-test.xml.
> But
> org.slf4j.LoggerFactory.getILoggerFactory().getLogger("xxx") can only get 
> current LoggerContext and read configuration from log4j2.xml.
>  
> Is it designed like this? Why?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to