3 Replies Latest reply on Mar 4, 2003 5:55 PM by petertje

    Logging in servlets and JSP'S

    oprins

      Hello,

      how can I use the log4j service from jboss in a servlet or a JSP. Is any example code available?

      Thanks
      Olaf

        • 1. Re: Logging in servlets and JSP'S
          joelvogt

          for a simple example try this:

          * include log4j.jar with your app
          * For each class you want to log add a category. ie:

          Class Foo, add:
          import org.apache.log4j.Category;

          static Category logCat =
          Category.getInstance(Foo.class.getName());

          Then when you want to go
          logCat.debug("msg");
          logCat.error("msg");
          logCat.info("msg");

          etc.

          Not sure how this will go for jsp though. Should still go.

          • 2. Re: Logging in servlets and JSP'S
            maxted

            Has anyone actually got this to work for JSPs?

            I'm using JBoss-2.4.4/Tomcat-3.2.3.

            As usual it's the deployment side where information seems
            to be lacking rather than the coding.

            I have also seen contradictory information on whether
            log4j.jar should be WEB-INF/lib and where to put the
            log4j.properties file!

            • 3. Re: Logging in servlets and JSP'S

              Well, i think that log4j is already on the jboss classpath, as it is heavily used by jboss itself, so you shouldn't have to worry about that.
              Within JBoss, the log4j.properties file is only used in the first phase of the startup: as soon as the JBoss log4j service is started, everything from this file is ignored. So you'd probably want to put your logj config stuff in the log4j.xml in the conf directory.

              Hth
              Peter

              Btw, if it doesn't work, tell us what is actually going wrong...