Setting logback.xml path programmatically

后端 未结 5 1122
我在风中等你
我在风中等你 2020-12-02 13:27

I know I can set the logback.xml path like this:

Specifying the location of the default configuration file as a system property

You may specif

5条回答
  •  伪装坚强ぢ
    2020-12-02 13:43

    I just want to share what I did in the end with a Jersey-Spring app:

    MyWebApplicationInitializer implements WebApplicationInitializer {
        @Override
        public void onStartup(final ServletContext servletContext) throws ServletException {
            servletContext.addListener(new LogbackConfigListener());
            try { LogbackConfigurer.initLogging(servletContext.getRealPath("/WEB-INF/logback.xml")); }
            catch (FileNotFoundException | JoranException e) { e.printStackTrace(); }
        }
    }
    

    I also have to add, that I had to move

    
        org.logback-extensions
        logback-ext-spring
        0.1.4
        compile
    
        ch.qos.logback
        logback-core
        1.2.3
        compile
    

    from runtime (parent project in my case) to compile.

提交回复
热议问题