要在运行时更改log4j属性,请访问此链接
http://alperkaratepe.wordpress.com/2010/01/16/how-to-change-log4j-properties-
at-runtime/
private void updateLog4jConfiguration(String logFile) { Properties props = new Properties(); try { InputStream configStream = getClass().getResourceAsStream( "/log4j.properties"); props.load(configStream); configStream.close(); } catch (IOException e) { System.out.println("Error: Cannot laod configuration file "); } props.setProperty("log4j.appender.FILE.file", logFile); PropertyConfigurator.configure(props); }


