Adjust Logging level for apache commons logging?

前端 未结 4 2036
攒了一身酷
攒了一身酷 2020-12-14 17:54

I have a simple console app which uses apache\'s PDFBox library, which in turn uses commons logging. I\'m getting a lot of junk messages in my console which I\'d like to sup

4条回答
  •  醉酒成梦
    2020-12-14 18:06

    In case you have no time to figure out which Logging implementation is used underneath by the Apache commons-logging, try to disable all that are in you classpath. Following code tests three implementations.

    If any of the lines doesn't compile, do not add the dependency! Just remove the line.

    String[] loggers = { "org.apache.pdfbox.util.PDFStreamEngine",
        "org.apache.pdfbox.pdmodel.font.PDSimpleFont", "httpclient.wire.header" , "httpclient.wire.content"
    for (String ln : names) {
      // Try java.util.logging as backend
      java.util.logging.Logger.getLogger(ln).setLevel(java.util.logging.Level.WARNING);
    
      // Try Log4J as backend
      org.apache.log4j.Logger.getLogger(ln).setLevel(org.apache.log4j.Level.WARN);
    
      // Try another backend
      Log4JLoggerFactory.getInstance().getLogger(ln).setLevel(java.util.logging.Level.WARNING);
     }
    

提交回复
热议问题