Search

B.2. Separate Log Files Per Application

download PDF
To segregate logging output per application, assign log4j categories to specific appenders. This is typically done in the conf/log4j.xml deployment descriptor.

Example B.2. Filtering App1 Log Output to a Separate File

 <appender name="App1Log" class="org.apache.log4j.FileAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
  <param name="Append" value="false"/>
  <param name="File" value="${jboss.server.home.dir}/log/app1.log"/>
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
  </layout>
</appender>

...

<category name="com.app1">
  <appender-ref ref="App1Log"></appender-ref>
</category>
<category name="com.util">
  <appender-ref ref="App1Log"></appender-ref>
</category>

Example B.3. Using TCLMCFilter

Enterprise Platform 5.1 includes the new class jboss.logging.filter.TCLMCFilter, which allows you to filter based on the deployment URL.
 <appender name="App1Log" class="org.apache.log4j.FileAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
  <param name="Append" value="false"/>
  <param name="File" value="${jboss.server.home.dir}/log/app1.log"/>
  <layout class="org.apache.log4j.PatternLayout">
	 <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
  </layout>
  <filter class="org.jboss.logging.filter.TCLMCFilter">
	 <param name="AcceptOnMatch" value="true"/>
	 <param name="DeployURL" value="app1.ear"/>
  </filter>    
  
  <!-- end the filter chain here -->
  <filter class="org.apache.log4j.varia.DenyAllFilter"></filter>

</appender>
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.