How to log with Ruby and eventmachine?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 09:47:26

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4156281/how-to-log-with-ruby-and-eventmachine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!