Hi everybody,
I have a problem:
I develop a web application, I want to create my log files in a Folder
in the context like this: $CATALINA_HOME/webapps/mywebapp/ $LOG_FOLDER.
I use my own FileAppender to create a log file every day which contains
the date in the name file. It is working!
I have tried to use the same behaviour to specify the folder but it's
not working! I give you the code, maybe someone can find an error
My log4j.properties
******************
log4j.rootLogger=INFO, file
log4j.appender.file=com.capgemini.gestion.GestionLogging
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm} %5p
[%t] (%F\:%L) - %m%n
#Before :
#log4j.appender.file.File=/tomcat/webapps/appWicket-1.0/logs/appWicket_%
date%.log
#Now :
log4j.appender.file.File=%path%/appWicket_%date%.log
log4j.appender.file.append=false
******************
Part of my FileAppender classe
******************
public void setFile(String strFile) {
String strDate;
SimpleDateFormat sdf;
// for the folder, create the link for the path
String real_path = ((WebApplication)
WebApplication.get()).getServletContext().getRealPath("/");
String name_log =
GestionProperties.getProperty("logRealdir");
String path_log = real_path+name_log;
Folder folder_log = new Folder(path_log);
if (!folder_log.exists())
folder_log.mkdir();
// replace %path% to path_log
strFile = strFile.replaceAll("%path%",
path_log);
if (datePattern!=null && strFile!=null) {
sdf = new
SimpleDateFormat(datePattern);
strDate = sdf.format(new Date());
fileName = [B]path_log +[/B]
strFile.replaceAll("%date%", strDate);
} else {
System.err.println("Either File or
DatePattern options are not set for appender [" + name + "].");
}
}
public String getDatePattern() {
return datePattern;
}
public void setDatePattern(String datePattern) {
this.datePattern = datePattern;
}
******************
If I remove the code include for the path folder, as said above, it's
working. But I have to specify manually the path folder, which could
change when machine server changes.
So how can I specify dynamically the log folder path?
Thank you in advance,