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); }