I wonder why do I have raised exception between the logger debug output?
DEBUG: asdjoasjd
DEBUG: asdjoasjd
DEBUG: asdjoasjd
**RuntimeError: something**
DEBUG: continued debug message
DEBUG: continued debug message
DEBUG: continued debug message
While this debug message were composed before the exception?
$stdout.sync = true not helped.
i'm using log4r
From the IO#sync documentation:
This means that Ruby won't buffer the data internally. Unfortunately this doesn't imply anything about any OS buffering and the OS might buffer the data as well.
Also note that Log4r uses IO#flush to flush data which guarantees that the data will be flushed to the underlying OS but nothing more as well.
What you need is IO#fsync which immediatelly writes (flushes) all buffered data.
You could subclass Log4r::StdoutOutputter and provide your own
#writeimplementation.Example:
Buffering is good and highly recommended for performance reasons, especially in production systems. Otherwise you run the risk of consuming unnecessary resources, such as putting unnecessary strain on your disks.
On a personal note, I think
Log4ris outdated and a bit inactive. I try to stick with either the nativeLoggeror at leastActiveSupport::Logger(which basically provides a formatter). Have a look at more modern alternatives such as logging. Most of the loggers are interchangeable.