java log4j的日志文件保存到项目发布目录

使用该种方式为什么根目录下没有响应的文件生成
public class log4jlistener implements ServletContextListener {

public static final String log4jdirkey = "log4jdir";

public void contextDestroyed(ServletContextEvent servletcontextevent) {

    System.getProperties().remove(log4jdirkey);

}


public void contextInitialized(ServletContextEvent servletcontextevent) {

    String log4jdir = servletcontextevent.getServletContext().getRealPath("/");

    //System.out.println("log4jdir:"+log4jdir);

    System.setProperty(log4jdirkey, log4jdir);

}

}

web.xml配置:

<listener-class>com.haier.framework.util.log4jlistener</listener-class>

需要配置log4j2.xml,参考这篇文章。

推荐用logback,是时候更新了

或者配置log4j.properties文件也可以