English 中文(简体)
delayed queries queries
原标题:Have delayed_job log "puts", sql queries and jobs status

如今只有以下几条被贴上<代码>logs/delayed_job.log/code>:

2012-04-20T03:57:44+0000: Cacher completed after 5.3676
2012-04-20T03:57:44+0000: 1 jobs processed at 0.1744 j/s, 0 failed ...

我想要做的是,它也要记录所有我的<代码>put。 我的问询,以及我的问询,如同在发展模式中所做的一样,但依然贴在<代码>log/delayed_job.log上。

我试图在<条码>上添加以下内容:初始用户/延迟_job_config.rb但无uck:

Delayed::Worker.logger = Rails.logger
Delayed::Worker.logger.level = Logger::DEBUG

(所有我<代码>puts) 如今已经停下来,但不再有工作身份记录,也没有问询。

最佳回答
问题回答

在铁路公司诉3.2.13案中,你可以:

Delayed::Worker.logger = ActiveSupport::Logger.new("log/delayed_job.log", Rails.logger.level)
Delayed::Worker.logger.auto_flushing = 1

#only reassign AR logger if we re in a delayed process(rake task or script/delayed_job)
if caller.last =~ /script/delayed_job/ or (File.basename($0) == "rake" and ARGV[0] =~ /jobs:work/)
  ActiveRecord::Base.logger = Delayed::Worker.logger
end

但... 主动支持:正在对以下项目进行折旧:

此外,你可能希望轮换你的标识? 因此,我认为这更好:

Delayed::Worker.logger = Logger.new("log/delayed_job.log", 5, 104857600)

if caller.last =~ /script/delayed_job/ or (File.basename($0) == "rake" and ARGV[0] =~ /jobs:work/)
  ActiveRecord::Base.logger = Delayed::Worker.logger
end

The constructor says keep around 5 log files and rotate when the current log file hits 100Mb. See here for details: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html#method-c-new

Credit to: http://www.heedspin.com/2011/01/17/delayed-job-logging.html for the inspiration

这对被占领土来说可能是很晚的,但这里采取不同的做法:使用一种拖延的焦布金来设定铁路(和活性记录:底线)与被指派给工人的木.。

两个步骤:在您的推迟工作初始者中:

require  delayed_job_log_setup 
Delayed::Worker.plugins << DelayedJobLogSetup

原始材料本身(我显然在校准/推迟_job_log_setup.rb):

require  delayed_job 

class DelayedJobLogSetup < Delayed::Plugin
  callbacks do |lifecycle|
    lifecycle.before(:execute) do |worker|
      Rails.logger = worker.logger
      ActiveRecord::Base.logger = worker.logger
    end
  end
end

不幸的是,我试图将 log子-拼凑起来的<代码>目标#puts直接称作 log(在gin子里)的尝试,仍然 t不去欧佩集团想要做的事情。

这样做的另一个办法是,在您的铁路申请中,在<代码>上填写必要的标识文件。 我们现在看着这一点。

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__),  .. ,  config ,  environment ))
require  delayed/command 

# This was added to make sure the DJ log has the same log level 
# as the rails app, and to ensure ActiveRecord uses the same log 
# when loaded inside a DJ worker process.
#
Delayed::Worker.logger ||= Logger.new(File.join(Rails.root,  log ,  delayed_job.log ), Rails.configuration.log_level)
ActiveRecord::Base.logger = Delayed::Worker.logger

Delayed::Command.new(ARGV).daemonize

这种做法十分简单、清晰。

更为重要的是,在不涉及延迟工人过程的假设情景下,不会出现忽略AR记录的风险。 对我们来说,这种做法与其他一些答案相似,造成许多头痛和混乱。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签