Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logrotate - String of junk at top of log files

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.

like image 417
whats canasta Avatar asked Sep 06 '13 00:09

whats canasta


1 Answers

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.

like image 190
Jeremy Avatar answered Nov 30 '22 22:11

Jeremy