-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
When the log4j.properties and log4j.xml both in classpath.
The log4j by default will load lo4j.xml instead of the log4j.properties. See :
org.apache.log4j.LogManager
url = Loader.getResource(DEFAULT_XML_CONFIGURATION_FILE);
if(url == null) {
url = Loader.getResource(DEFAULT_CONFIGURATION_FILE);
}
But if I config the loggerFactory by using foundation log in log4j.xml like:
<loggerFactory class="com.cisco.oss.foundation.logging.FoundationLogFactory"/>
The log4j load the configuration in the xml file OK, BUT:
When loggerFactory create foundation logger. It ONLY load from "log4j.properties": see com.cisco.oss.foundation.logging.FoundationLogger
if (resource == null) {
resource = Loader.getResource(DEFAULT_CONFIGURATION_FILE); // NOPMD
}
if (resource == null) {
System.err.println("[FoundationLogger] Can not find resource: " + DEFAULT_CONFIGURATION_FILE); // NOPMD
thrownew FoundationIOException("Can not find resource: " + DEFAULT_CONFIGURATION_FILE); // NOPMD
}
// update the log manager to use the Foundation repository.
final RepositorySelector foundationRepositorySelector = new FoundationRepositorySelector(FoundationLogFactory.foundationLogHierarchy);
LogManager.setRepositorySelector(foundationRepositorySelector, null);
It will result the configuration in log4j.xml is overridden by what in the log4j.properties. For example, the level of the logger.
Metadata
Metadata
Assignees
Labels
No labels