Skip to content

add support for log4j.xml #5

@dindinw

Description

@dindinw

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions