maven apache
2010-12-27 06:26:22 UTC
Hi:
I want the logs created by log4j put under the app dir,so I set the
placeholder in the log4j.properties:
# chartstdout is set to be a ConsoleAppender.
log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender
log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout
log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x -
%m%n
log4j.appender.chartfileout=org.apache.log4j.FileAppender
log4j.appender.chartfileout.File=${apppath}/logs/log.html
log4j.appender.chartfileout.Append=true
log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout
log4j.rootLogger=debug, chartstdout,chartfileout
Then in my servlet whose "load-on-startup" attribute is "0" I set the
property "apppath",but it does not work.
It seems that the log4j read the log4j.properties and config the log before
I modify the property.
public void init() {
DbManager.init();
// log
String context =
getServletConfig().getServletContext().getRealPath("/");
Properties p = new Properties();
p.setProperty("apppath", context);
try {
p.load(InitServlet.class.getResourceAsStream("/log4j.properties"));
} catch (IOException e) {
e.printStackTrace();
}
PropertyConfigurator.configure(p);
}
Of course,I can rename the log4j.properties,then the log4j will not find the
file but I can. However some other libs which I used in my appliction
require log4j also,they need the log4j.properties to generate there logs.
Any ideas?
I want the logs created by log4j put under the app dir,so I set the
placeholder in the log4j.properties:
# chartstdout is set to be a ConsoleAppender.
log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender
log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout
log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x -
%m%n
log4j.appender.chartfileout=org.apache.log4j.FileAppender
log4j.appender.chartfileout.File=${apppath}/logs/log.html
log4j.appender.chartfileout.Append=true
log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout
log4j.rootLogger=debug, chartstdout,chartfileout
Then in my servlet whose "load-on-startup" attribute is "0" I set the
property "apppath",but it does not work.
It seems that the log4j read the log4j.properties and config the log before
I modify the property.
public void init() {
DbManager.init();
// log
String context =
getServletConfig().getServletContext().getRealPath("/");
Properties p = new Properties();
p.setProperty("apppath", context);
try {
p.load(InitServlet.class.getResourceAsStream("/log4j.properties"));
} catch (IOException e) {
e.printStackTrace();
}
PropertyConfigurator.configure(p);
}
Of course,I can rename the log4j.properties,then the log4j will not find the
file but I can. However some other libs which I used in my appliction
require log4j also,they need the log4j.properties to generate there logs.
Any ideas?