Load Log4j2 configuration file programmatically

后端 未结 8 1503
-上瘾入骨i
-上瘾入骨i 2020-12-14 14:51

I want to load Log4j2 XML configuration file programmatically from my application.

Tried this:

ConfigurationSource source = new ConfigurationSource()         


        
8条回答
  •  既然无缘
    2020-12-14 15:14

    If you have a single main entry point, this code snippet might save you some trouble. The set property call must fire before any loggers are created. This approach works with files on the classpath.

    public class TestProcess {
        static {
            System.setProperty("log4j.configurationFile", "log4j-alternate.xml");
        }
    
        private static final Logger log = LoggerFactory.getLogger(TestProcess.class);
    
    }
    

提交回复
热议问题