Logrotate - String of junk at top of log files

1.8k Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.