首页 > 代码库 > log

log

 

    <servlet> 
        <servlet-name>log4jInit</servlet-name> 
        <servlet-class>com.isoftstone.servlet.Log4JInit</servlet-class> 
        <init-param> 
            <param-name>log4j-config-file</param-name> 
            <param-value>/WEB-INF/classes/conf/log4j.properties</param-value> 
        </init-param> 
        <load-on-startup>1</load-on-startup> 
    </servlet>


package com.isoftstone.servlet;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.log4j.*;
/**
 * log4jInit load
 * @author King
 * @time 2014-09-23
 */
public class Log4JInit extends HttpServlet {
    public void init() throws ServletException {
        String prefix = getServletContext().getRealPath("/");
        String webappHome = getServletContext().getRealPath("");
        System.setProperty("webappHome", webappHome);
        String file = getServletConfig().getInitParameter("log4j-config-file");
        System.out.println("loading log4j>>>>>>>>>>>>>>>>>>>>"+prefix + file);
        // 从Servlet参数读取log4j的配置文件
        if (file != null) {
            PropertyConfigurator.configure(prefix + file);
        }
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    }
}

 

log