简体   繁体   中英

using SLF4J to Bridge JUL does't work

I'm currently observing that a 3rd party library (namely javax.mail ) is using java.util.logging. The version of javaMail is 1.4.7. I want to use SLF4J LoggingFramwork to bridge JUL to logback. the slf4j api version is : logback-core|1.0.13
slf4j-api|1.7.5
jul-to-slf4j|1.7.5

In the main function, I'm also install SLF4JBridgeHandler programmatically by invoking:

 // Optionally remove existing handlers attached to j.u.l root logger
   SLF4JBridgeHandler.removeHandlersForRootLogger();  

 // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
 // the initialization phase of your application
  SLF4JBridgeHandler.install();

but it does'twork, the javaMail also log debug info in my console. my logbak.xml is

  <root level="INFO">
      <appender-ref ref="STDOUT" />
   </root>

is there something wrong?

With session debugging turned on JavaMail can directly write to System.out. It is possible that is the reason you are seeing the console output. Try turning it off :

    Session s = Session.getInstance(props);
    s.setDebug(false);

Otherwise you can change the logger level for the JavaMail loggers.

java.util.logging.Logger.getLogger("javax.mail").setLevel(Level.WARNING);

The root JavaMail logger name is 'javax.mail'. See java.util.logging: how to set level by logger package (or prefix)? for other ways to change the logger level.

JavaMail 1.3 FCS RELEASE was the first release that supported debuging via an output stream. By default System.out is returned as the default debug stream. JavaMail 1.4.6 was the first release that was adapted to use java.util.logging. The previous behavior is still supported for legacy applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM