I have a web application in Tomcat that uses log4j for logging.
If I delete the log files while the web application is running the files are not recreated?
How can I
If your tomcat is on a linux server, and you start it with a specific user that doesn't have execute rights on the log folder, your log4j will not recreate your logs, because probably it has only read/write rights.
If this is the case try a:
chmod 755
on the containing folder
EDIT:
The second possibility is that some operating systems complete the "delete" operation only when the file is not in use anymore. If this is the case your tomcat can still "see" the log as there.
EDIT2:
In that case make a cron job that every several minutes checks if the file is there. If not just recreate it. I will provide a solution in a few minutes.
So the bash that should be in your crontab would have something like:
if [ ! -f /tomcat_dir/log4j.log ]
then
`touch /tomcat_dir/log4j.log`;
fi