2 Replies Latest reply on Feb 2, 2016 1:15 PM by rnikander

    JUL Logger.getLogger(name) returning different objects?

    rnikander

      Hi,

       

      Isn't `java.util.logging.Logger.getLogger(String)` supposed to return the same object when called with same string.  I get different objects, even when calling it one after another in the same function.  This is Wildfly 9.0.1.  Some calls are in my web apps `ServletContextListener`, others are `Servlets`.

       

      I noticed this when I set a Logger's `useParentHandlers` to false in my context listener, but later saw that property was true on the Logger used by the Servlet.

       

      Rob

        • 1. Re: JUL Logger.getLogger(name) returning different objects?
          jameslivingston

          I don't believe that the j.u.l API guarantees that, "Logger objects may be obtained by calls on one of the getLogger factory methods. These will either create a new Logger or return a suitable existing Logger."

           

          In the case of JBoss LogManager, it returns a new Logger object on each call, however that is only a thin facade over a LoggerNode which is shared between all the Loggers for the same name.

          • 2. Re: JUL Logger.getLogger(name) returning different objects?
            rnikander

            Thanks, that clarifies it. I configuring my logging with jboss-cli.sh and everything is working.

             

            I'm not going to dig into this now, but I do wonder about j.u.l.Logger.getLogger. The javadoc on the method says this:

            "If a logger has already been created with the given name it is returned. Otherwise a new logger is created."