1 Reply Latest reply on Feb 26, 2003 1:25 PM by Mikael Eriksson

    Using Log4J NDC with EJBs

    tim kitchens Newbie

      I'm using Log4J's Nested Diagnostic Context (NDC) to trace logging statements across the Web-EJB tier. For example, I have a servlet that pushes some request-specific info (i.e. username/IP/timestamp) onto the NDC stack and then calls an EJB. It appears that JBoss is popping the NDC stack before I invoke the EJB, as the stack only contains the name of the EJB (which I never put there) when the call reaches the EJB.

      Can anyone tell me whether there's a simple way to get around this? Or, possibly point me to the class where the NDC stack is being popped for EJB's?

      Thanks,
      Tim

        • 1. Re: Using Log4J NDC with EJBs
          Mikael Eriksson Novice

          (Copy of another in persistence CMP from me)

          This happened to me too, and I did some checking.

          It seems that everywhere that JBoss code does
          a NDC.push()/pop() it also does a NDC.remove().

          This feels like a bug and that the NDC.remove() only
          should be called when the thread itself is removed.
          (Have not gotten around to file a report about it though)

          To get around this I used the log4j.MDC instead and
          updated the config file to display a MDC.

          Ex: log4.xml %X{user} is the MDC


          Then I do a
          MDC.put("user", userInfo);
          at the start of every request in the web layer.
          (userinfo is username + remote ip addr btw)

          I have not tested this under load yet, but so far the same thread seems to be used all the way down to the EJB layer.

          Regards
          /Mikael