如何使用Ruby和eventmachine登录? [英] How to log with Ruby and eventmachine?

查看:83
本文介绍了如何使用Ruby和eventmachine登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby和Eventmachine库编写应用程序.我非常喜欢非阻塞I/O和事件驱动系统的想法,我遇到的问题是日志记录.我正在使用Ruby的标准记录器库.它并不是永久地记录日志,但似乎不应该阻止它并且它确实可以阻止.是否有某个地方可以将Ruby的标准记录器实现扩展为非阻塞库,还是应该仅将EM :: defer调用以进行记录调用?有没有一种方法可以让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?

推荐答案

我最终将记录器包装在一个启动线程并具有FIFO队列的单例类中.日志记录会将日志信息转储到队列中,并且线程刚刚循环,将内容从队列中拉出,然后使用真实的记录器对其进行日志记录.并不是真正的反应堆模式,但是它也不会占用我的EM线程池.

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.

有了这个单例,您将只能拥有一个记录器,但这是我在 github 上所做的工作

With this singleton, you can only ever have one logger but here is what I did up on github.

这篇关于如何使用Ruby和eventmachine登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆