使用JBoss配置web application的logj

如果不使用JBoss配置Log4j,则需要一个WEB-INF下的log4j.properties,需要在web.xml中添加
<servlet>  
   		<servlet-name>log4j-init</servlet-name> 
   		<servlet-class>com.web.config.Log4jInit</servlet-class>
   		<init-param>
    		<param-name>log4j</param-name>
      		<param-value>WEB-INF/log4j.properties</param-value>
   		</init-param> 
   		<load-on-startup>1</load-on-startup>
	</servlet> 

在com.web.config.Log4jInit中:
public class Log4jInit extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void init() {
		String prefix = getServletContext().getRealPath("/");
		String file = getInitParameter("log4j");
		if (file != null) {
			PropertyConfigurator.configure(prefix + file);
		}
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res) {
	}
}


------------------------------------

如果使用JBoss配置Log4j,log4j.properties不需要,web.xml也不需添加,也不需要Log4jInit。

修改jboss-log4j.xml,加入:
<appender name="LOG_NAME" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/****.log"/>
      <param name="Append" value="false"/>
	  
      <!-- Rollover at midnight each day -->
      <param name="DatePattern" value="'.'yyyy-MM-dd"/>

      <!-- Rollover at the top of each hour
      <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
      -->

      <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>
      <filter class="org.jboss.logging.filter.TCLFilter">
         <param name="AcceptOnMatch" value="true"/>
         <param name="DeployURL" value="WarName.war"/>
      </filter>
      <!-- end the filter chain here -->
      <filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
</appender>


   <category name="com.apple.ist.sgweb" additivity="false">
     <!-- priority value can be changed to DEBUG, WARN, ERROR, FATAL, TRACE, 
     			this modification need not restart jboss -->
     <priority value="INFO"/>
     <appender-ref ref="LOG_NAME"/>
   </category>


你可能感兴趣的:(thread,Web,xml,log4j,jboss)