I need that log4j create automatically the log folder because of i cannot
create this folder in other environments.
If directory exist log4j works fine and the program generates log correctly.
Version of log4j is 1.2.12 although i have tested version 1.2.15 too.
I added "log4j.appender.xxx.autoCreate=true" in the log4j.properties but it
is the same.
In other apps Log4j does create folder before it store the log files.
More information:
------- ------- -------
------- ------- -------
------- -------
log4j.properties.
log4j.appender.xxx=org.apache.log4j.FileAppender
log4j.appender.xxx.File=C:/logFolder/xxx/file.log
log4j.appender.xxx.Append=true
log4j.appender.xxx.Threshold=DEBUG
log4j.appender.xxx.MaxFileSize=3000KB
log4j.appender.xxx.MaxBackupIndex=50
log4j.appender.xxx.layout=org.apache.log4j.PatternLayout
log4j.appender.xxx.layout.ConversionPattern=%-5p [%d{dd MMM yyyy
HH:mm:ss}] [%C{2}:%L] --> %m%n
log4j.rootLogger=DEBUG, xxx
------- ------- -------
------- ------- -------
------- -------
class
public class LogInit extends HttpServlet{
public void init() throws ServletException{
String prefix =
getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
// if the log4j-init-file is not set, then no point in
trying
if(file != null) {
PropertyConfigurator.configure(prefix+file);
}
}
}
------- ------- -------
------- ------- -------
------- -------
web.xml
<servlet>
<servlet-name>LogInit</servlet-name>
<servlet-class>package.LogInit</servlet-class>
<init-param>
<param-name>log4j-init-file</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>