1

I am using logrotate to manage my logs. As I have to manage a bunch of log files. My logrotate config looks like

/log/typeA*.log
/log/typeB*.log
/log/typeC*.log{
        daily
        rotate 7
        copytruncate
        size 1M
        compress
        su root root
        create 0644 root root
        missingok
}

After logrotation is complete I see bunch of null characters in the beginning of file. Which looks like

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

Looks like infinitely long string. Also file size looks similar. There is solution suggested https://serverfault.com/a/510470 to use postrotate script like

postrotate
   sed -i -e 's/\o00//g' session.timing.1
endscript

But as I am applying this to bunchg of files I don't have any specific name like session.timing.1 is there any way to get it done generically? I want this operation to be done for all file of typeA_date1.log typeA_date2.log and so on.... Or do you suggest any other method that can be useful here?

1 Answer 1

0

i get the same problem. After read the logrotate code, i think when the program keep writing log message with a opened file, can only use copytruncate mode, but this mode also makes file hole by ftruncate and fill with NULL characters.

Some tips:

  1. change the program method for log, which not need use copytruncate mode
  2. managed by systemd with syslog configure, see how to
  3. managed by systemd (version 236 or newer) which can set StandardOutput to a file, so maybe can use logrotate with create mode (not sure)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .