How to clean catalina.out without disabling further registration?

From time to time, our catalina.out file gets very large (yes, I use slf4j and logback in my applications to prevent this from happening again). But now, when I move on to the cycle of magazines, I copy catalina.out for catalina. {Date} and execute cat /dev/null > catalina.out. The problem is that tomcat will not write any subsequent logs after I do this until tomcat is restarted the next morning, and this is not ideal. Why is this happening? And is there a way to avoid this?

+4
source share
4 answers

Easy as pie: echo > catalina.out. The file descriptor will not change, and javamay continue to write to this file.

+9
source

The traditional way is

cat /dev/null > catalina.out

It will clear the log file and will not disrupt the processes in which open files are currently stored.

It is best not to lose registration information by turning the log file. To do this, create or edit a file /etc/logrotate.d/tomcatand read its contents.

/var/log/tomcat/catalina.out {   copytruncate   daily   rotate 7   compress   missingok   size 5M  }

Then restart logrotate using the command (with root privileges)

/usr/sbin/logrotate /etc/logrotate.conf

And you need the log file to rotate daily, or if the size exceeds 5M, and the last seven logs are saved for debugging purposes.

+6
source

. , , .

truncate -s 0 M catalina.out

FYI: cat /dev/null > file .

logs]$ls -i test.log
19794063 test.log
logs]$
logs]$cat /dev/null > test.log
logs]$ls -i test.log
19794063 test.log

, , test.log. test.log - . , , inode.

+3

, , . , , . . Tomcat Wiki.

+1

All Articles