5 Replies Latest reply on Feb 20, 2002 10:25 AM by adrian.brock

    Log4j custom Category in jboss-3.0.0alpha

    forourke

      I have my own log4j Category which I am trying to use in jboss-3.0.0alpha. My Category extendy the log4j Category and I have a CategoryFactory which accesses my custom category. I am using the standard jboss log4j.properties file which defines its own CategoryFactory.

      I cannot get this to work inside jboss.
      With my custom log4j category packaged with my beans, I get the following error

      I have tried putting my custom log4j into a separate jar file in the jboss lib/ext directory. This works the first time. However if I redeploy my bean and I get the following error.
      [11:13:11,171,Proxies] unexpected error
      java.lang.ClassCastException: org.apache.log4j.Category

      Also if I put any calls System.out.println(); in my Category and Factory, it crashes jboss.

      If I use the log4j Category directly everything works fine and I can hot redeploy my beans with no problems.

      Has anyone got their own Category factory working inside jboss???

        • 1. Re: Log4j custom Category in jboss-3.0.0alpha

          Hi,

          Use "search" to see other discussion on log4j config.

          JBoss uses log4j. This means you have to play fair if you
          want to reconfigure log4j.
          If you break JBoss because of your changes it is your
          problem.

          There are two problems with log4j at the moment.

          1) It uses Class.forName() to load custom classes.
          This is "wrong". Log4j was written to support java 1,
          since java2 the correct method is
          Thread.currentThread().getContextClassLoader().loadClass();

          2) Everybody shares the same logging universe. Your app
          and JBoss have to use the same configuration.

          Both of these problems will be fixed when log4j 1.2
          is released. Currently, it is an alpha release.

          With log4j 1.2, JBoss will be able to provide a
          separate logging universe for each application.
          This will allow you to reconfigure at much as you like,
          without worrying about breaking JBoss.

          Incidently, in log4j 1.2 Category is deprecated and
          has changed in an incompatible way.
          You will have problems with any code that sub-classes
          Category.

          Regards,
          Adrian

          • 2. Re: Log4j custom Category in jboss-3.0.0alpha
            forourke

            My problem seems to be that defining a
            private static final ITrace in my entity bean causes jboss to give a EXCEPTION_ACCESS_VIOLATION (see attached file). The

            // causes jboss to crash
            private static final ITrace trace = TraceFactory.getInstance(MemberImpl.class);

            // works fine
            private static final Category trace = Category.getInstance(MemberImpl.class);

            My TraceFactory is a wrapper for the Category similar to the Logger that is proposed with log4j1.2.

            Any ideas on why I get the exception and what is causing it.


            • 3. Re: Log4j custom Category in jboss-3.0.0alpha

              That's a bizarre one.
              An access violation occurs when you try to
              introspect something that you should not be looking at,
              e.g. a private field.

              It might be a problem in the proxy compiler?
              Sorry, I don't know much about it.
              But, it is more likely a classloader problem.

              Where are the classes TraceFactory and ITrace?

              Regards,
              Adrian

              • 4. Re: Log4j custom Category in jboss-3.0.0alpha
                forourke

                The TraceFactory and ITrace are in my jar file which also contains the beans that are deployed.

                • 5. Re: Log4j custom Category in jboss-3.0.0alpha

                  I guess that is the problem.

                  The classloader for log4j cannot
                  see your classes (they are in a child classloader).

                  Try splitting out the log4j customization classes into a
                  separate jar and putting them lib/ext

                  Depending upon your version of 3.0 you will have to
                  modify the list of jars at the top of jboss-service.xml

                  In 2.4.x you would have to modify the
                  archives attribute of log4jservice in jboss.conf

                  Regards,
                  Adrian