0

I am trying to silence logback's internal logging that occurs when the configuration is reloaded. I looked at this question, as well as this one, and I tried each of the recommended solutions. However, this case seems to be a little different. For the most part, logback is well behaved. Before I reload, and once the reload is done, it emitts no peeps, but when the reload is running, it logs a ton of stuff.

I tried:

  1. Setting the ch.qos logger to WARN.
  2. The configuration was always debug="false".
  3. Using encoders rather than layouts.
  4. Added a NopStatusListener to the configuration.
  5. Upgraded to latest logback (1.1.2)
  6. Ensured there were no errors. Nothing other than INFO messages are logged.
  7. Tried using a filter to deny any ch.qos events that were not > INFO.
  8. There is only one logback.xml in the classpath, although I also have a file-logback.xml in the same directory which is the switch I am making which causes this chatty logging, but I don't think that file gets in the way. (All the above items are applicable to both files, and I tried renaming the file-logback.xml to something cryptic to make sure it was not being picked up by mistake)

I suspect the problem is that when one calls ch.qos.logback.classic.jmx.JMXConfiguratorMBean.reloadByURL, it first resets the configuration, then loads the new one. In the interrim, there is neither one configuration in effect, or the other, so the fallback is to log at INFO.

Any suggestions on how to quiet this guy down a bit ?

Thanks.

Community
  • 1
  • 1
Nicholas
  • 15,916
  • 4
  • 42
  • 66

1 Answers1

0

I guess actually writing a question on stack shook up the brain cells a bit. So I fixed this by calling the JoranConfigurator directly and skipping the reset process. In addition, I removed the STDOUT appender from the root logger (since the purpose is to switch from STDOUT to file logging).

    final URL url = Main.class.getClassLoader().getResource("file-logback.xml");
    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        final JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        configurator.doConfigure(url);
        final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.detachAppender("STDOUT");
        log.info("Set internal logback config with file [{}] and roll pattern [{}]", logFileName, rollPattern);
    } catch (JoranException je) {
        System.err.println("Failed to configure internal logback");
        je.printStackTrace(System.err);
    }                                               
Nicholas
  • 15,916
  • 4
  • 42
  • 66