简体   繁体   English

Rails发条在日志上显示

[英]Rails clockwork display on log

I'm trying to learn how to use the gem clockwork . 我正在尝试学习如何使用宝石clockwork I'm just trying to test on my Mac and putting a line onto the development log. 我只是想在Mac上进行测试,并在开发日志中添加一行。 I have it set at 3 minutes just for testing. 我将其设置为3分钟以进行测试。

I have the following in lib/clock.rb : 我在lib / clock.rb中有以下内容:

require 'clockwork'
module Clockwork
  handler do |job|
    puts "Running #{job} =================================="
  end
Clockwork.every(3.minutes, 'dailyjob')
end

Then I have lib/tasks/dailyjob.rb 然后我有lib / tasks / dailyjob.rb

class DailyJob
  def perform
    Rails.logger.info "Daily Job ========================================="
  end
end

I then start Clockworks via the console $ clockwork clock.rb . 然后,我通过控制台$ clockwork clock.rb启动Clockworks。 It starts up and every 3 minutes the console says: 它启动,控制台每3分钟显示一次:

Running dailyjob ==================================
I, [2014-03-04T11:03:32.084240 #66442]  INFO -- : Triggering 'dailyjob'

But, nothing shows up in the development.log file. 但是,development.log文件中没有任何内容。

Thanks for the help! 谢谢您的帮助!

Per docs , Clockwork will only write to STDOUT unless you configure it otherwise: 根据文档 ,Clockwork只会写入STDOUT,除非您进行其他配置:

By default Clockwork logs to STDOUT. 默认情况下,发条盒记录到STDOUT。 In case you prefer your own logger implementation you have to specify the logger configuration option. 如果您更喜欢自己的记录器实现,则必须指定记录器配置选项。 See example below. 请参见下面的示例。

Example from the docs is this: 来自文档的示例是这样的:

module Clockwork
  configure do |config|
    config[:sleep_timeout] = 5
    config[:logger] = Logger.new(log_file_path)
    config[:tz] = 'EST'
    config[:max_threads] = 15
    config[:thread] = true
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM