1 Reply Latest reply on Nov 6, 2002 2:26 PM by adrian.brock

    Logging from an EJB in JBoss

    benj

      I understand that JBoss uses Log4J for its logging implementation.

      I am trying to find out how to perfom logging from an EJB.
      I understand that I/O operations are forbidden from an EJB context. Does Log4J work around this?

      I have also encoutered org.jboss.ejb.plugins.LogInterceptor. Is that what I should use for logging from EJB calls?

      If this is the case, then I would really like to call these from a standard interface.

      Say Logger.logSomething(x, y ....) which would act as a proxy, delegating calls either to Logger or LogInterceptor. Does the jboss logger automatically do this for me?

      If not, the problem I envisage in writing this proxy is determining whether the caller is an ejb or is in a web-app context. How would I implement this? I am loathed to try and create an InitialContext each time I want to log something ( to check the environment ), and the thought of passing in a reference the calling class also fills me with dread. Has anyone got any ideas about this? Or at least could point me to some resources?

      Thanks

      Ben

        • 1. Re: Logging from an EJB in JBoss

          Just log as normal. I would recommend a static logger.

          Direct I/O is forbidden by spec, but you will find
          that you can still do it. The container can do I/O
          for you, you can probably consider log4j as part of the
          container.

          The only thing to worry about is that the console and
          file appenders are potentially blocking i/o operations,
          that can cause your ejb to stop.

          I wouldn't recommend using the console appender in
          production, especially on windows.

          In production, you can always change the threshold
          so that nothing is logged anyway.

          Regards,
          Adrian