文章来源:http://blog.sina.com.cn/s/blog_a1304cff0101c9bb.html
在cxf的webService下用log4j居然不好使?
log4j.properties是正确的,在其他工程中日志都正常写到文件中。
后来终于解决了此问题
新建一个servlet,强制加载log4j配置文件。
public class Log4jConfig extends HttpServlet {
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {}
public void init() throws ServletException {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j");
if(file != null){
PropertyConfigurator.configure(prefix+file);
}
}
}
web.xml 增加如下输入:
<servlet>
<servlet-name>log4jConfig</servlet-name>
<servlet-class>Conf.Log4jConfig</servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value>WEB-INF\classes\log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>