3

Whenever log4j2's RollingFileAppender rotates a log file on my web server (when the first entry is written on a new day) the available disk space shrinks considerably.

I use log4j-1.2.17.jar.

lsof shows deleted files, which can't be freed because they are in use by my java process.

For instance, the file FOP.log was rotated to FOP.log.2016-04-13.gz which apparently worked well, but now

[crauser@localhost logs]$ lsof | grep "/" | grep deleted
java      3204 crauser    1w      REG              253,0  10486278 1054558 /home/crauser/cra.decap/decap.interface/logs/cra_decap_consumer.log.5 (deleted)
java      3204 crauser    2w      REG              253,0  10486278 1054558 /home/crauser/cra.decap/decap.interface/logs/cra_decap_consumer.log.5 (deleted)

shows 270 times the file FOP.log.2016-04-13 (without the gz suffix).

These undeleted files eat up several GB of disk space.

These files are gone as soon as I kill java process, but restarting by killing process is not an option.

Is there a way to prevent this file handle leak?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • see this [answer](https://stackoverflow.com/a/38138070/2310289) – Scary Wombat Feb 05 '18 at 05:41
  • Possible duplicate of [catalina.out rolling with Tomcat 6.0](https://stackoverflow.com/questions/1146759/catalina-out-rolling-with-tomcat-6-0) – uli Feb 05 '18 at 05:46
  • https://stackoverflow.com/a/38138070/2310289 , this did nt solve my problem as it is related to having two appenders which is writing in console and file. In my case, its the problem with rolling of logs. the last log file will be deleted but process doesnt release the space and it keeps growing in several GBs.. – user2075355 Feb 05 '18 at 06:25
  • @user2075355 Just curious, were you able to figure out how to solve this issue? I am facing a similar issue and for now I restart the Java process every now and then but I think there should be a better way to solve this issue – Salem Artin May 28 '19 at 05:25

0 Answers0