[ https://issues.apache.org/jira/browse/LOG4J2-960?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Remko Popma resolved LOG4J2-960. -------------------------------- Resolution: Fixed Fix Version/s: (was: 2.5) 2.4 I see what you mean: ConfigurationFactory has only two abstract methods: {code} public abstract Configuration getConfiguration(ConfigurationSource source); protected abstract String[] getSupportedTypes(); {code} When creating a custom ConfigurationFactory you naturally assumed that all you need to do was implement these methods, and that's where you run into the problem you describe above. The solution is simply to also override the {{getConfiguration(String name, URI configLocation)}} method, and return your custom configuration from both {{getConfiguration}} methods. I think the real problem here is that until version 2.4, it was not easy for users to find out how to programmatically configure Log4j. Version 2.4 introduced the [ConfigurationBuilder|http://logging.apache.org/log4j/2.0/manual/customconfig.html#ConfigurationBuilder] API, and simultaneously improved the documentation with more examples. The new docs show an [example custom ConfigurationFactory|http://logging.apache.org/log4j/2.0/manual/customconfig.html#Example] that overrides both the {{getConfiguration}} methods. I am resolving this issue as Fixed given that the documentation has been improved. Please reopen if you disagree, or close if this makes sense. > Custom ConfigurationFactory that uses no configuration file will never be used > ------------------------------------------------------------------------------ > > Key: LOG4J2-960 > URL: https://issues.apache.org/jira/browse/LOG4J2-960 > Project: Log4j 2 > Issue Type: Bug > Components: Configurators > Affects Versions: 2.1 > Environment: log4j 2.1, Java 1.7 > Reporter: Daniel Fowler > Labels: configuration, newbie > Fix For: 2.4 > > > If I create a custom ConfigurationFactory that accepts all configuration > files (getSupportedTypes() returns String[] {"*"}) and do not specify a > configuration file via the System property 'log4j.configurationFile' then the > ConfigurationFactory that I specify will never be used. > In org/apache/logging/log4j/core/config/ConfigurationFactory.java in method > 'public Configuration getConfiguration(final String name, final URI > configLocation)' configLocation will be null and when trying to load the > configuration file System property for String config it will be null. > The execution in the method will then skip down to these lines: > Configuration config = getConfiguration(true, name); > if (config == null) { > In this case the custom configuration factory will not be used because in the > method 'private Configuration getConfiguration(final boolean isTest, final > String name)' skips over all configuration factories that return 'null' or > 'String[] {"*"}' for factory.getSupportedTypes(). Therefore it will return > null and eventually the Default configuration will be used. > Therefore it is impossible to use a custom ConfigurationFactory without > specifying the the System property 'log4j.configurationFile' which the > documentation (http://logging.apache.org/log4j/2.0/manual/configuration.html) > seems to imply should be programmatically permissible. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org