DAddYE / foreverb

Small daemon framework for ruby, with logging, error handler, scheduling and much more.

Home Page:https://github.com/DAddYE/foreverb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Truncating logfile is difficult

niko opened this issue · comments

I don't know if that's an issue but I noticed that truncating the logfile (the redirected STDOUT) doesn't work, at least the way expected. When doing

echo '' > out.log
ls -l out.log

ls still shows the old filesize. df shows the diskspace being freed. The logfile contains somehow invisible characters. It seems the open file should be rewinded or seek the beginning again. I work around this with this code at the moment:

Signal.trap('USR2'){ STDOUT.truncate 0 ; STDOUT.rewind }

To reproduce see https://gist.github.com/1564418

Hey, sorry for my late reply, yep, what about logrotate?

I don't know what logrotate does exactly. I suppose it moves the old file an expects the process to then write to the new file. But for that the process must repoen the file otherwise the process continues to write to the old file. unicorn does this for example on USR1 (see http://unicorn.bogomips.org/SIGNALS.html). The problem is that trapping a signal overrides old traps. So just using one signal (say USR1) could collide with app specific traps. I've no idea how to solve this in a general way. :(