Log4j 指定日志文件

  InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/
config/log4j.properties");
        Properties p=new Properties();
        try {
            p.load(in);
            PropertyConfigurator.configure(p);
            logger.info("load log4j.properties ");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

   log4j2指定配置文件:

  

public  static void loadLog4j2Xml(String log4j2xmlClassPath) throws Exception {
        ClassPathResource classPathResource = new ClassPathResource(log4j2xmlClassPath);
        ConfigurationSource configurationSource = new ConfigurationSource(classPathResource
.getInputStream());
        Configurator.initialize(null, configurationSource);
    }

猜你喜欢

转载自java12345678.iteye.com/blog/2382722