Log4j does not recreate files on deletion

前端 未结 5 2113
面向向阳花
面向向阳花 2020-12-19 12:33

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

5条回答
  •  旧时难觅i
    2020-12-19 12:50

    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
    

提交回复
热议问题