Ruby 有统一的日志系统吗?
我想知道是否有真正统一的日志系统可以支持 Rails 和延迟作业,并且相对容易设置。
我希望能够为我的应用程序中的任何执行上下文(Rails、延迟作业等)登录到同一服务器/文件,即使我当前不在 Rails 上下文中。
喜欢 Rails 记录器,但我在 Resque 工作时无法登录它。有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是指类似于系统日志的文件记录器吗?
Ruby 同时具有
Logger
和Syslog
。Logger 可以进行日志滚动、处理严重性级别,并在许多 Ruby 模块中用于日志记录。您可以定义要记录的文件的名称,或使用 STDOUT/STDERR 或 IO 流。
syslog 的文档非常简单,但是您可以通过浏览其源代码或阅读 Ruby Syslog 自述文件。
Do you mean a file-logger, similar to syslog?
Ruby's got both
Logger
andSyslog
.Logger can do log rolling, handles severity levels, and is used in a lot of Ruby modules for logging. You can define the name of the file to log to, or use STDOUT/STDERR or an IO stream.
The docs for syslog are pretty barebones, but you can get info by browsing its source code, or reading the Ruby Syslog README.
我必须记录由 resque 作业运行的 gem 中发生的事情。为了记录 Rails 数据库中发生的情况,我执行以下操作:
这样我可以记录不同进程中发生的情况,还可以按 Foo 实例的 object_id 过滤日志,因此只记录相关数据。
I have to log things that are happening in a gem which runs by a resque job. To log what is going on to Rails database I do the following:
This way I can log things which are happening in different process and also filter logs by object_id of the Foo instance, so only relevant data gets logged.