lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

Fluentd cannot detected log being rotating

Open jhowliu opened this issue 5 years ago • 7 comments
trafficstars

As title, Is it possible integrate with fluentd in-tail?

Fluentd stop updating the pos-file when rotation happened.

jhowliu avatar Feb 14 '20 15:02 jhowliu

I see the same issue with simply 'tail'. If I run 'tail -F logfile' and the file gets rotated, tail doesn't detect the change (even though the '-F' flag should guarantee it).

Mathiasdm avatar Dec 17 '20 10:12 Mathiasdm

I'm not sure how tail and fluentd work in this case. I can look into it. There may be some file descriptor magic logrotate etc do to keep tail on the right track.

natefinch avatar Dec 17 '20 12:12 natefinch

To add to this, I was able to solve the issue for tail by using 'tail -F --max-unchanged-stats=5 logfile', which reloads the file when it no longer changes. Using only '-F', I noticed that tail kept looking at the moved file (according to what I saw in /proc//fd/ ).

Mathiasdm avatar Dec 17 '20 15:12 Mathiasdm

Yeah, that makes sense. Tail would follow the file descriptor, even if the name changed. When lumberjack rotates, it just renames the old file, which would keep the same file descriptor. I would need to look at how to fix that. I could copy the file and truncate the original, but then we'd have that file's contents on disk twice, and that could mean you'd be using too much disk space (although I guess that's the same disk space you'd use once the original file fills up to capacity, too. Hmm.)

natefinch avatar Dec 17 '20 15:12 natefinch

Yes yes, that's what & why I wrote in https://github.com/natefinch/lumberjack/issues/115#issuecomment-739835573

phuslu avatar Dec 18 '20 03:12 phuslu

I could copy the file and truncate the original

the copyturncate option which like logrotate do is a bad idea,

  1. it's not safe.
  2. it will introduce a heavy load and causes a large performance downgrade in a high-qps server.

Many companies (include us) were encountered the 2nd issue.

phuslu avatar Dec 18 '20 03:12 phuslu

A related issue https://github.com/logrotate/logrotate/issues/269 and https://github.com/logrotate/logrotate/pull/361

phuslu avatar Dec 18 '20 04:12 phuslu