[
https://issues.apache.org/jira/browse/LOG4J2-3677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17781056#comment-17781056
]
Jiazhou Gao commented on LOG4J2-3677:
-------------------------------------
Hi [~vy] , yes it is still a issue to me.
My code snippet
{code:java}
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
public class MyXmlConfigurationFactory extends ConfigurationFactory {
/**
* Valid file extensions for XML files.
*/
public static final String[] SUFFIXES = new String[]{".xml"};
@Override
protected String[] getSupportedTypes() {
return SUFFIXES;
}
@Override
public Configuration getConfiguration(LoggerContext loggerContext,
ConfigurationSource source) {
System.out.println("Getting log4j2 configuration from
MyXmlConfigurationFactory");
return new MyXmlConfiguration(loggerContext, source);
}
/**
* This class extends the built-in XmlConfiguration so after the standard xml
configuration completes the custom configuration can be added to it.
*/
private class MyXmlConfiguration extends XmlConfiguration {
public MyXmlConfiguration(LoggerContext loggerContext, final
ConfigurationSource configSource) {
super(loggerContext, configSource);
}
@Override
protected void doConfigure() {
System.out.println("Configuring log4j2 with MyXmlConfigurationFactory");
super.doConfigure();
}
}
}
{code}
Some other class logs something that would trigger the configuration
When I started my JVM with
-Dlog4j2.configurationFactory=com.xxx.MyXmlConfigurationFactory nothing printed
in standard out
while after I changed it to
-Dlog4j.configurationFactory=com.xxx.MyXmlConfigurationFactory everything
worked fine
Btw, I noticed in ConfigurationFactory code
[https://github.com/apache/logging-log4j2/blob/19f4050ef1d6d4b074327b26c5921c327d670c5a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java#L83]
It says "log4j.configurationFactory" is the CONFIGURATION_FACTORY_PROPERTY, so
it makes sense to me that log4j.configurationFactory would work
but i don't understand how log4j2.configurationFactory was able to work in the
first place
> System property log4j2.configurationFactory doesn't work
> --------------------------------------------------------
>
> Key: LOG4J2-3677
> URL: https://issues.apache.org/jira/browse/LOG4J2-3677
> Project: Log4j 2
> Issue Type: Bug
> Reporter: Jiazhou Gao
> Assignee: Volkan Yazici
> Priority: Major
>
> We followed the wiki
> [https://logging.apache.org/log4j/2.x/manual/customconfig.html]and set
> -Dlog4j2.configurationFactory=<our customized configuration factory> in Java
> opts.
> It used to work but seems broken after log4j2 2.17.1. Our
> configurationFactory never started
> Now, we have to use system property log4j.configurationFactory and set
> -Dlog4j.configurationFactory=<our customized configuration factory> in Java
> opts
> So it looks like a regression in log4j2 latest versions
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)