log4j的配置方法:
参考链接:
http://www.codejava.net/coding/how-to-initialize-log4j-for-java-web-application
大致3种思路:
1.把log4j.properties文件放在WEB-INFO/下面或者,放在src/下面。这样他最终会打包到WEB-INFO/classes/目录下。在程序中直接使用即可,不需再调用PropertyConfigurator.configure("log4j.properties");
2.通过ServletContextListener的初始化函数。例如:
java代码:
@Override public void contextInitialized(ServletContextEvent event) { // initialize log4j here ServletContext context = event.getServletContext(); String log4jConfigFile = context.getInitParameter("log4j-config-location"); String fullPath = context.getRealPath("") + File.separator + log4jConfigFile; PropertyConfigurator.configure(fullPath); }
需要设置初始化参数 <context-param>
3.通过一个启动时就进行初始化的Servlet进行初始化。
请参考
http://www.avajava.com/tutorials/lessons/how-do-i-initialize-log4j-in-a-web-application.html
相关推荐
chw0 2020-11-04
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
丨Fanny丨Cri 2020-05-17
JavaWinner 2020-05-10
JavaWinner 2020-05-04
CXC0 2020-04-20
CXC0 2020-04-10
丨Fanny丨Cri 2020-02-18
MrLiar 2020-02-16
CXC0 2020-02-09