Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

If you're on a system with Syslog you can take a look at EM-Syslog

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top