1

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?

smart
  • 89
  • 1
  • 2
  • 7

1 Answers1

0

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.

Community
  • 1
  • 1
jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • In my environment , the javaMail debugging maybe turned on default. How can I turn the log off ? – smart Nov 05 '14 at 13:20
  • the java.util.logging.Logger.getLogger("javax.mail").setLevel(Level.WARNING); command does't work .Sorry I forget the detail. I'm using org.springframework.mail.javamail.JavaMailSenderImpl which use javaMail under the hook to send Email.Does that impact the log? – smart Nov 06 '14 at 01:21
  • Shouldn't change anything. Does setting session.setDebug(false) work? The only other thing I've noticed is that MailLogger used in JavaMail might cache stale values for debug boolean and debugOut printstream. That might be a bug you are seeing. – jmehrens Nov 06 '14 at 14:33