Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log with Ruby and eventmachine?

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?

like image 976
Justin Avatar asked Nov 11 '10 15:11

Justin


2 Answers

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.

like image 119
Justin Avatar answered Oct 16 '22 05:10

Justin


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

like image 36
dj2 Avatar answered Oct 16 '22 04:10

dj2