Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Basically, they rely on file system to flush logs. If you want to restore old behavior, it's restored fairly simply along the lines of:

    file = File.open("log/production.log", "w")
    file.sync = true
    Rails.logger = ActiveSupport::BufferedLogger.new(file)


I think you have to add some code flushing the BufferedLogger after each request to really get the old behavior.

But this is not my point, for me rails has been about sane defaults - this is what makes it fun to start and easy to work with. I just don't see why we fix something that is not broken at all.


No. Flushing in buffered logger is a number of no-ops. Check the commit itself.

They decided to get rid of supposedly unneeded cruft that was hard to maintain and delegate file handling functions to OS.


Does this work? There's a lot of removed code in that commit, does this replicate the old behavior?


I have reread the comments, rechecked the current state of ruby code, and have an impression that might answer came off as ambiguous.

1. This commit changed two things: default file mode of open logs is no more sync in production (i.e. it is not automatically flushed by ruby write routines) AND it doesn't buffer log entries anymore (which is actually funny, since, you know, it is called ActiveSupport::BufferedLogger) 2. When IO#sync is false, which was the case, ruby didn't flush upon every write. That manifested itself in logfile entries not appearing immediately after write. 2.1. In some 3.2 release they've reversed that, so sync = true is by default in all latest versions of rails. 3. Since logger doesn't buffer requests anymore, the problem of interleaving messages should still be there, sorry for confusion. 3.1. To solve this, you can either use tag features of recent rails or port older buffered logger itself.


Most of the code deleted was related to locking around writes and flushing the buffer. Also, lots of specs testing the said behavior.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: