红宝石守护程序引起的ActiveRecord记录仪IO错误 [英] Ruby Daemons causing ActiveRecord logger IOError

查看:189
本文介绍了红宝石守护程序引起的ActiveRecord记录仪IO错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的时刻在Ruby中它利用ActiveRecord的宝石进行数据库交互的一个项目,我想使用的ActiveRecord :: Base.logger <记录所有的数据库活动/ code>属性有以下code

I'm writing a project at the moment in Ruby which makes use of the ActiveRecord gem for database interaction and I'm trying to log all the database activity using the ActiveRecord::Base.logger attribute with the following code

ActiveRecord::Base.logger = Logger.new(File.open('logs/database.log', 'a'))

这工作正常迁移等(由于某种原因似乎需要日志记录启用为它提供了NilClass错误被禁用时),但是当我尝试运行,其中包括一个线程后台程序调用ActiveRecord的对象脚本项目失败,出现以下错误

This works fine for migrations etc (which for some reason seem to require that logging be enabled as it gives a NilClass error when it's disabled) but when I try to run the project which includes a threaded daemon calling the ActiveRecord object the script fails with the following error

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/logger.rb:504:in `write': closed stream (IOError)

在如何解决这个问题的任何想法将不胜AP preciated。目前我已经开始期待通过其他code,看的人有实现的ActiveRecord记录更线程安全的方式的其他方式

Any ideas on how to solve this problem would be greatly appreciated. For the moment I've started to look through other code to see if people have other ways of implementing ActiveRecord logging in a more thread-safe manner

感谢

帕特里克

推荐答案

我碰到了同样的问题。请先守护进程,和的然后的加载Rails环境。

I ran into the same issue. You need to daemonize first, and then load the Rails environment.

这篇关于红宝石守护程序引起的ActiveRecord记录仪IO错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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