I'm writing an application using Ruby and the Eventmachine library. I really like the idea of non blocking I/O and event driven systems, the problem I'm running into is logging. I'm using Ruby's standard logger library. Its not that logging takes forever but it seems like something that shouldn't block and it does. Is there a library out there somewhere that extends Ruby's standard logger implementation to be non-blocking or should I just call EM::defer for my logging calls? Is there a way I can make eventmachine do this for me already?
I ended up wrapping the logger in a singleton class that started a thread and had a FIFO queue. Logging would dump log info into the queue and the thread just looped, pulling stuff out of the queue and using the real logger to log it. Not really reactor pattern but it won't chew up my EM thread pool either.
With this singleton, you can only ever have one logger but here is what I did up on github.
If you're on a system with Syslog you can take a look at EM-Syslog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With