0

My Scala-application uses Play Framework 2.1 together with SolrJ (V. 4.0) to communicate with Solr.

  • When I run my tests (play test) I get a very long annoying list of DEBUG org.apache.http.* messages from SolrJ. :-(
  • When I run my application (play run) no debug-message from SolrJ appears. :-)

In conf/application.conf all logger levels are set to INFO:

logger.root=INFO
logger.play=INFO
logger.application=INFO

I even try to create my own conf/application-logger.xml file, but the DEBUG-messages from Solrj stay the same.

How can I get rid of the DEBUG-messages durring testing?

I have read an old Stackoverflow-Question about this, but the answers don't work (I think it was a question for Play 1).

4

1 回答 1

1

您可以尝试在 Java 代码中动态修改日志级别。

 private static void modifyLogLevel() {
    @SuppressWarnings("unchecked")
    Enumeration<Logger> e = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
    while (e.hasMoreElements()) {
        Logger curLogger = e.nextElement();
        if (curLogger.getName().contains("org.apache")){
            curLogger.setLevel(Level.INFO);
        }
    }
    Properties props = new Properties();
    props.put("log4j.logger.org.apache","ERROR");
    PropertyConfigurator.configure(props);}
于 2013-02-27T08:43:40.347 回答