You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "francis (Jira)" <ji...@apache.org> on 2021/12/30 17:04:00 UTC
[jira] (LOG4J2-3304) SpringEnvironmentHolder getEnvironment always return null
[ https://issues.apache.org/jira/browse/LOG4J2-3304 ]
francis deleted comment on LOG4J2-3304:
---------------------------------
was (Author: JIRAUSER281512):
I am using SpringBoot 2.1.1.RELEASE. The code marked with red color below is the key, {color:#172b4d}LogManagerStatus.isInitialized() return false because LogManagerStatus.{color}setInitialized is not called while the property log4j2.loggerContextFactory is present and load successfully, in the static block of LogManager.{color:#172b4d} so the method getEnvironment will never execute the if block and environment will be always null{color}
{code:java}
// code placeholder
public class SpringEnvironmentHolder {
private volatile Environment environment;
private Lock lock = new ReentrantLock();
protected Environment getEnvironment() {
if (environment == null && LogManagerStatus.isInitialized() && LogManager.getFactory() != null &&
LogManager.getFactory().hasContext(SpringEnvironmentHolder.class.getName(), null, false)) {
lock.lock();
try {
if (environment == null) {
Object obj = LogManager.getContext(false).getObject(Log4j2CloudConfigLoggingSystem.ENVIRONMENT_KEY);
environment = obj instanceof Environment ? (Environment) obj : null;
}
} finally {
lock.unlock();
}
}
return environment;
}
} {code}
> SpringEnvironmentHolder getEnvironment always return null
> ---------------------------------------------------------
>
> Key: LOG4J2-3304
> URL: https://issues.apache.org/jira/browse/LOG4J2-3304
> Project: Log4j 2
> Issue Type: Bug
> Components: API, Spring
> Affects Versions: 2.17.1
> Reporter: francis
> Priority: Major
>
> I am using SpringLookup and SpringProfileArbiter for conditional configuration, but it doesn't work. I debugged into SpringEnvironmentHolder and found that the getEnvironment method always returns null. Then I found the root cause is that when the factoryClassName is present and load successfully, the LogManagerStatus is not set in the static block of LogManager. It could be a bug, please take a look
--
This message was sent by Atlassian Jira
(v8.20.1#820001)