What is right way to supply initialization for log4j2 in a Spring MVC Webapp using Java Config and no web.xml?

前端 未结 3 833
青春惊慌失措
青春惊慌失措 2021-01-22 15:59

I have a Spring MVC Web App (4.0) with log4j2. This webapp uses no web.xml and takes care of configuration through Java Config. Log4j2 configuration needs to take plac

3条回答
  •  终归单人心
    2021-01-22 16:56

    Probably this is a little too late, but you can do the following to set the log4j2 configuration to an external path:

    public class ApplicationInitializer implements WebApplicationInitializer {
        @Override
        public void onStartup(ServletContext servletContext)
            throws ServletException {
            servletContext.setInitParameter(Log4jWebSupport.LOG4J_CONFIG_LOCATION, "file:///path/to/log4j2.xml");
    

提交回复
热议问题