0

I used logrotate to rotate my log files. The conf file look like this:

/data/log/web/12114.log {

    daily

    rotate 10

    copytruncate

}

But logrotate doesn't cut the log file properly. The result log files look like this:

-rw-r--r-- 1 root root           0 12月 21 03:14 12114.log

-rw-r--r-- 1 root root 12806139570 12月 21 10:55 12114.log-20151217

-rw-r--r-- 1 root root           0 12月 17 03:13 12114.log-20151218

-rw-r--r-- 1 root root           0 12月 19 03:15 12114.log-20151219

-rw-r--r-- 1 root root           0 12月 20 03:28 12114.log-20151220

-rw-r--r-- 1 root root           0 12月 21 03:14 12114.log-20151221

Which means all the logs were written to 12114.log-20151217, the should-be file 12114.log-20151221 has no content.

Why could this happen? The log file were written from flask logger utils.

Thx in advance,

Diamond
  • 9,001
  • 3
  • 24
  • 38
alex
  • 1

1 Answers1

0

Logrotate just moves/renames the file, but your snippet above will do nothing to tell the running process that the file has been moved. You will need a postrotate stanza in your logrotate config that tells the process to reopen its log file, closing the moved one and opening the original again.

Craig Miskell
  • 4,216
  • 1
  • 16
  • 16
  • No, this should be wrong because alex is using `copytruncate`. However it looks like something else may be overriding this logrotate entry and that something does not have `copytruncate` and also no postrotate that signals the correct process. – wurtel Dec 21 '15 at 13:06
  • You make a splendid point; with only 5 lines of config I don't know how I missed the copytruncate. I have seen problems with Java and copytruncate before, but not as presented above. – Craig Miskell Dec 23 '15 at 08:19