Uploaded image for project: 'Terrier Core'
  1. Terrier Core
  2. TR-111

Terrier breaks existing log4j configuration

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 4.0
    • Component/s: None
    • Labels:
      None

      Description

      Terrier always reconfigures log4j and thus breaks a log4j configuration that may have been set up by the environment in which Terrier is run. One way of avoiding this is try figuring out if log4j already was configured and if so not try to configure it again. A simple check would be to test if any appenders for the root logger are configured already:

      {code}
      //setup log4j
      if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
      if (new File(LOG4J_CONFIG).exists())
      {
      DOMConfigurator.configure(LOG4J_CONFIG);
      }
      else
      {
      //slightly ugly hack: record a good default configuration as a String in this class, and load that
      //emulating DOMConfigurator.configure(Reader)
      //see http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java?revision=311462&view=markup
      new DOMConfigurator().doConfigure(new StringReader(DEFAULT_LOG4J_CONFIG), org.apache.log4j.LogManager.getLoggerRepository());
      }
      }
      {code}

      A more sophisticated example of how to check this can be found here: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/logging/Log4jLoggerImpl.java?view=markup in the method isLog4JConfigured() (Apache License obviously).

        Attachments

          Issue Links

            Activity

            Hide
            craigm Craig Macdonald added a comment -

            Nice catch. I have seen this in Hadoop where the logging changes once Terrier is started.

            Show
            craigm Craig Macdonald added a comment - Nice catch. I have seen this in Hadoop where the logging changes once Terrier is started.
            Hide
            craigm Craig Macdonald added a comment -

            I tried both these solutions, and it prevented the Terrier log4j configuration from being loaded.

            Show
            craigm Craig Macdonald added a comment - I tried both these solutions, and it prevented the Terrier log4j configuration from being loaded.
            Hide
            craigm Craig Macdonald added a comment -

            Tagging for 3.1, will see if I can find a solution.

            Show
            craigm Craig Macdonald added a comment - Tagging for 3.1, will see if I can find a solution.
            Hide
            craigm Craig Macdonald added a comment -

            Gave a bit more look at this. The issue is that the Hadoop configuration is loaded before ApplicationSetup, hence the default loggers are normally:

            [org.apache.log4j.ConsoleAppender@43684706, org.apache.hadoop.metrics.jvm.EventCounter@730efd7c]
            
            Show
            craigm Craig Macdonald added a comment - Gave a bit more look at this. The issue is that the Hadoop configuration is loaded before ApplicationSetup, hence the default loggers are normally: [org.apache.log4j.ConsoleAppender@43684706, org.apache.hadoop.metrics.jvm.EventCounter@730efd7c]

              People

              • Assignee:
                craigm Craig Macdonald
                Reporter:
                rec Richard Eckart de Castilho
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: