Where do I find my whenever log files?

4.7k Views Asked by At

I'm using the whenever gem for Rails 5. I'm trying to troubleshoot an issue, and after my default schedule.rb file was created at config/schedule.rb, I added some logging directives

# 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

I restarted my Rails server (not sure if that matters or not) but I don't see these log files created anywhere. I have verified my crontab was set up by running "crontab -e" and seeing the job

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 '

Where are the log files created?

2

There are 2 best solutions below

2
On

In your schedule.rb file you can specify the redirection options for your commands at a global or command level by setting the 'output' variable. This example is global level:

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

and you should put this global level set :output above your job definition, otherwise it wouldn't work Example:

# 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

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

0
On

According to whenever documentation https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

you can define output like this with Rails :

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

So for your exemple you can do :

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