6 Replies Latest reply on Nov 5, 2005 7:25 AM by jaikiran

    Combine Log4J of JBoss and JDK-Log of own EJBs

      Hi *,

      my EJBs use JDK-Logging. It's possible to configure it by usage of a propperties file assigned at server start (VMArg).
      JBoss uses Log4J. In the log4j.xml file the location of log folder is set.

      <param name="File" value="${jboss.server.home.dir}/log/server.log"/>


      Now the question: How can my beans log to the folder defined for JBoss Logging? The JDK Switches for location configuration are very limited. Is it possible to achieve this without code-changes in EJBs or exchanging JDK-API by Log4J-API (I don't want to use AOP or something like that)?

      Would be nice if someone could help me.
      Thx. Per

        • 1. Re: Combine Log4J of JBoss and JDK-Log of own EJBs
          jaikiran

          You can use log4j for logging from the EJBs. There's one log4j.xml in server/default/conf where you can specify the settings for log4j. However, if you want a specific log4j.xml for your application, you can also do that.
          Please, have a look at:

          http://wiki.jboss.org/wiki/Wiki.jsp?page=Logging




          • 2. Re: Combine Log4J of JBoss and JDK-Log of own EJBs

            Thanks jaikiran for the reply. I haven't read the wiki. Sorry for that.

            I decided to use the "Redirecting Category Output" task to solve my problem.
            Added an appender and the top level package category to log4j.xml.
            The problem is that the log-file is empty.

            Here is what i added:


             <appender name="ApplLog" class="org.apache.log4j.FileAppender">
             <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
             <param name="Append" value="false"/>
             <param name="File" value="${jboss.server.home.dir}/log/my-appl.log"/>
             <layout class="org.apache.log4j.PatternLayout">
             <!-- The default pattern: Date Priority [Category] Message\n -->
             <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
            
             <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
             <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
             -->
             </layout>
             </appender>
            
            ...
            
             <!-- Limit the top level application package -->
             <category name="de.myfirm" additivity="false">
             <priority value="INFO"/>
             <appender-ref ref="ApplLog"/>
             </category>
            


            Looked at many examples but haven't found any solution. Is it possible that this is only working if the EJBs are logging by usage of log4j?

            Thx
            Per

            • 3. Re: Combine Log4J of JBoss and JDK-Log of own EJBs
              jaikiran

              Let me explain, the way log4j looging works in jboss. During jboss startup there is a LoggingService that is started. This service reads a log4j.xml file present in server/default/conf directory and creates appropriate appenders. (Thats the reason why your my-appl.log file is created). Then whenever a logging statement is issued from some class, using a logger, through log4j's API then the appropriate appenders are used to log the message. To see the log messages in the my-appl.log file, you will have to log4j APIs in your EJBs. Try it out, its simple.

              • 4. Re: Combine Log4J of JBoss and JDK-Log of own EJBs
                jaikiran

                This link will get you started with log4j, if you are not familiar with it:

                http://www.developer.com/open/article.php/3097221

                • 5. Re: Combine Log4J of JBoss and JDK-Log of own EJBs

                  Ok, thanks.
                  That means that the answer to my second question

                  Is it possible to achieve this without code-changes in EJBs or exchanging JDK-API by Log4J-API (I don't want to use AOP or something like that)?

                  is NO.

                  • 6. Re: Combine Log4J of JBoss and JDK-Log of own EJBs
                    jaikiran

                    Please have a look at:

                    JDK java.util.logging section at:

                    http://wiki.jboss.org/wiki/Wiki.jsp?page=Logging

                    I guess, this is exactly what you are looking for. You need NOT have to change your existing code. However, i think you will have to introduce a new class, which is described in that section.