CopyTruncate log rotation mechanism is dropping logs

1.8k views Asked by At

I had implemented a linux based logrotation with copytruncate strategy. Below is the config for same:

/data/app/info.log {
missingok
copytruncate
maxsize 50M
daily
rotate 30
create 644 app app
delaycompress
compress
}

With above config, whenever logrotation task is triggered with application simultaneously writing logs, some log lines are getting dropped. Can someone please guide what am I doing wrong or suggest any other log rotation strategy with no data loss.

1

There are 1 answers

0
user16384485 On

I know this question is a few months old but simply for the benefit of others: You are not doing anything wrong. From the manpage

copytruncate: Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place."