【问题标题】:Where do I find my whenever log files?我在哪里可以找到我的每当日志文件?
【发布时间】:2018-02-21 08:25:12
【问题描述】:

我正在使用 Rails 5 的每当 gem。我正在尝试解决问题,在 config/schedule.rb 创建默认 schedule.rb 文件后,我添加了一些日志记录指令

# Learn more: http://github.com/javan/whenever
set :environment, "development"

every 10.minutes do
  rake "events:calc_index", :output => {:error => 'error.log', :standard => 'cron.log'}
end

我重新启动了我的 Rails 服务器(不确定这是否重要),但我没有在任何地方看到这些日志文件。我已通过运行“crontab -e”并查看作业来验证我的 crontab 是否已设置

0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /Users/davea/Documents/workspace/newproj && RAILS_ENV=development bundle exec rake events:calc_index '

日志文件在哪里创建?

【问题讨论】:

    标签: ruby cron ruby-on-rails-5 whenever logfile


    【解决方案1】:

    在您的 schedule.rb 文件中,您可以通过设置“输出”变量在全局或命令级别为您的命令指定重定向选项。这个例子是全局级别的:

      # adds ">> /path/to/file.log 2>&1" to all commands
      set :output, '/path/to/file.log'
    

    你应该把这个全局级别集 :output 放在你的工作定义之上,否则它不会工作 示例:

    # This works
    set :output, {:error => '~/Desktop/z.error.log', :standard => '~/Desktop/z.standard.log'}
    
    every 1.minute do
      command "python ~/Desktop/whe/config/z.py"
    end
    

    取自:https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

    【讨论】:

    • 是的,但是您正在硬编码“~/Desktop/z.error.log”,并且该目录结构并不存在于我的所有环境中。所以我的问题仍然存在,我设置了你在我的问题中看到的输出,那么这些文件将在哪里生成?
    • 你可以只使用 rails.env 来设置路径或任何配置
    【解决方案2】:

    根据任何时候的文档 https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

    你可以用 Rails 定义这样的输出:

    set :output, "#{path}/log/cron.log"
    

    因此,以您为例,您可以这样做:

    every 10.minutes do
      rake "events:calc_index", output: {error: "#{path}/log/error.log", standard: "#{path}/log/cron.log"}
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      相关资源
      最近更新 更多