5 Replies Latest reply on Jul 21, 2004 2:38 PM by Tim Shaw

    Log4J configuration (again!)

    Tim Shaw Newbie

      Hi,

      I have checked (and tried various suggestions) for this - but I can't get the behaviour I want ... [JBoss 3.2.5, JDK 1.4.2_04]

      I have an .ear containing an EJB .jar and 2 .wars. I want the .wars to log into distinct files.

      I tried putting log4j.xml in each WEB-INF/classes of the .wars (with the appropriate mappings) and log4j.jar into WEB-INF/lib.
      The docs said I should then override the classloading - this doesn't work as only the root context can do this.
      I tried using a log4jServlet approach (using DOMConfigurator etc), but this just seems to (almost randomly - based on timing I guess) kick all logging to one of the configurations ... even though the other files are created, they are empty.

      Is there anyone out there who has got a similar approach working ... or knows how it can be done?

      Many Thanks

      tim

        • 2. Re: Log4J configuration (again!)
          Tim Shaw Newbie

          Tried the logging stuff on the Wiki (all of it!) before I posted.

          The below log4j.xml causes all 3 'custom' files to contain the same output.
          a) Perhaps the Filter doesn't work
          b) Perhaps I am using the wrong string for the DeployURL
          c) Perhaps this approach doesn't work with filtering 'contained' .war files (i.e. only works for the top level .ear
          d) Perhaps I just got it wrong ...

          My understanding is that all application logging should go to myco.log, all 'supplier' logging (i.e generated from the Supplier.war code etc) should go to supplier.log (and sim. for administrator). I think I shall probably have to repackage into 2 .ears - but this is not what I wanted to do.










































          <!-- Limit MyCo categories to DEBUG -->





          <appender-ref ref="MYCO"/>
          <appender-ref ref="SUPPLIER"/>
          <appender-ref ref="ADMINISTRATOR"/>


          • 3. Re: Log4J configuration (again!)
            Tim Shaw Newbie

            Oops! Sorry

            <appender name="MYCO" class="org.jboss.logging.appender.FileAppender">
             <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
             <param name="File" value="/var/log/jboss/myco.log"/>
             <param name="Append" value="false"/>
            
             <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d [%t] %-5p [%c{4}] %m%n"/>
             </layout>
            
             <filter class="org.jboss.logging.filter.TCLFilter">
             <param name="AcceptOnMatch" value="true"/>
             <param name="DeployURL" value="MyCo.ear"/>
             </filter>
             </appender>
            
             <appender name="SUPPLIER" class="org.apache.log4j.FileAppender">
             <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
             <param name="Append" value="false"/>
             <param name="File" value="/var/log/jboss/supplier.log"/>
             <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d [%t] %-5p [%c{4}] %m%n"/>
             </layout>
             <filter class="org.jboss.logging.filter.TCLFilter">
             <param name="AcceptOnMatch" value="true"/>
             <param name="DeployURL" value="Suppliers.war"/>
             </filter>
             </appender>
            
             <appender name="ADMINISTRATOR" class="org.apache.log4j.FileAppender">
             <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
             <param name="Append" value="false"/>
             <param name="File" value="/var/log/jboss/administrator.log"/>
             <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d [%t] %-5p [%c{4}] %m%n"/>
             </layout>
             <filter class="org.jboss.logging.filter.TCLFilter">
             <param name="AcceptOnMatch" value="true"/>
             <param name="DeployURL" value="Administrators.war"/>
             </filter>
             </appender>
            
             <!-- Limit MyCo categories to DEBUG -->
             <category name="com.myco">
             <priority value="DEBUG"/>
             </category>
            
             <root>
             <appender-ref ref="MYCO"/>
             <appender-ref ref="SUPPLIER"/>
             <appender-ref ref="ADMINISTRATOR"/>
             </root>
            



            • 4. Re: Log4J configuration (again!)
              jamesstrachan Newbie

              Try something like this, which uses package names to separate the streams :-

              <appender name="MYCO">
               etc.
              </appender>
              
              <appender name="SUPPLIER">
               etc.
              </appender>
              
              <logger name="com.company.myco" additivity="false">
               <level value="ERROR"/>
               <appender-ref ref="MYCO"/>
              </logger>
              
              <logger name="com.company.supplier" additivity="false">
               <level value="DEBUG"/>
               <appender-ref ref="SUPPLIER"/>
              </logger>
              
              


              The example is incomplete but shows the principle.

              All events fron classes in packages commencing "com.company.supplier" will be sent to appender SUPPLIER, etc. The additivity flag prevents the events from "bubbling up" and being reported by appenders further up the chain. You don't need any filters.

              James


              • 5. Re: Log4J configuration (again!)
                Tim Shaw Newbie

                Thanks, but that's just basic log4j stuff.

                Like a good person, I have a (fairly large) number of shared packages between my 2 web-apps - and I need the logging to be in the correct file depending one who's calling them (app1 or app2).

                When I had this problem with straight Tomcat, I had to create separate wars with the log4j stuff in each (xml and jar). This, at least, allowed me total control over the logging for each one.
                This approach doesn't seem to work within the JBoss environment - I presume because the classloading causes the LoggingContext singleton to remain just that - a singleton!

                I think I need a way to force the log4j instances to sit within the war-file's classloader (and thus have a singleton for each war which will get found first) ... which is what I hoped would happen with the ' Using your own log4j.xml file' description on the wiki page. However, it would appear that this doesn't work as I can't override the LoaderRepository except in the 'top-level' (ie at the ear level) ... and I need it for each war.

                I have separated my app into an EJB jar and 2 wars, and deployed them separately - which seems a little more controllable using the filter - but I think I should be able to take these 3 standalone deployments and place them in an ear and get the same behaviour!

                Thanks for your suggestions so far.

                tim