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

    Logging in servlets and JSP'S

    Olaf Prins Newbie


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


        • 1. Re: Logging in servlets and JSP'S
          Joel Vogt Master

          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 =

          Then when you want to go


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

          • 2. Re: Logging in servlets and JSP'S
            Paul Maxted Newbie

            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
              Peter Doornbosch Apprentice

              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.


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