I've recently set up the following logrotate job:
/var/log/app.*.log {
daily
rotate 7
copytruncate
nocompress
dateext
}
I've found that when I go to view my log files, they start with some binary junk. I have to grep using --text and loading the files in vim takes forever.
Is this expected? Is there anything I can do to prevent it?
Note: logs used to be utf8 text files.
I had this same problem. I found the issue was that I was outputting to the log instead of appending. For example:
./application > logfile.log
when it should be:
./application >> logfile.log
What happens is the copytruncate on logrotate moves the file, output then seems to try to write to the same position and fills the file with a lot of hex fluff. This changes the file to be detected as a binary file instead of a text file.
After changing to append, I have not had this issue again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With