每当gem:我设置:output,但日志文件没有显示在我期望的位置 [英] whenever gem: I set :output but the logfile doesn't show up where I'd expect it to
问题描述
在我的 schedule.rb
文件中,有以下几行:
In my schedule.rb
file I have the following lines:
set :output, '/log/cron_log.log'
every 5.minutes do
command 'echo "hello"'
end
我每次在 Rails,无论何时在开发中使用gem ,我都假定cronfile已编写并正在运行。 (我也尝试过重新启动Rails服务器。)
I ran whenever -w
as suggested in this question Rails, using whenever gem in development, and I assume the cronfile is written and running. (I tried restarting the Rails server as well.)
当我运行 $ crontab -l </ code>时,我看到了以下:
And when I run $ crontab -l
I see the following:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash
-l -c 'echo "hello" >> /log/cron_log.log 2>&1'
但我找不到日志文件。我检查了rails_project / log,〜/ log和/ log无济于事。在OSX btw上。
But I can't find the log file. I checked in rails_project/log, ~/log and /log to no avail. On OSX btw.
如何将日志文件写入Rails项目日志文件夹?
推荐答案
您的日志在哪里?
您要将输出文件放在最高目录级别:
Where is your log?
You're putting the output file at the highest directory level:
$ cd /log
要查看文件是否存在以及文件中是否包含数据:
To see if the file exists and if it has data in it:
$ ls -la cron_log.log
根据需要创建日志文件:
To create the log file if needed:
$ touch cron_log.log
打开您的权限自己的本地调试(请勿在生产环境中执行!)
To open up permissions for your own local debugging (do NOT do this in production!)
$ chmod +rw cron_log.log
命令是否正在运行?
要手动运行命令以找出答案如果它按您的预期工作:
Is your command running?
To run the command manually to find out if it works as you expect:
$ /bin/bash -l -c 'echo "hello" >> /log/cron_log.log 2>&1'
为提高安全性并保护您的路径,使用完整路径:
To improve your security and protect your path, use full paths:
wrong: command 'echo "hello"'
right: command '/bin/echo "hello"'
查找命令的完整路径:
$ which echo
$ sudo grep CRON /var/log/syslog
grep结果中应包含以下内容:
The grep result should have lines that something like this:
Jan 1 12:00:00 example.com CRON[123]: (root) CMD (... your command here ...)
您在Mac上吗?
如果您未在系统日志中看到输出,而您正在使用Mac,您可能需要阅读有关Mac OSX从 cron
转换为 launchd
的信息。
请参阅cron plist(/System/Library/LaunchDaemons/com.vix.cron.plist)并用作tdout / stderr调试cron本身的路径。我不记得是否足以启动launchctl并加载plist来启动launchctl,或者因为它是系统守护程序,所以您必须完全重新启动。 (请参阅狮子中的cron日志文件在哪里 )
See the cron plist (/System/Library/LaunchDaemons/com.vix.cron.plist) and use a stdout/stderr path to debug cron itself. I don't recall if launchctl unloading and launchctl loading the plist is sufficient, or since it's a system daemon if you'd have to restart entirely. (see where is the cron log file in lion)
要相对于Rails应用程序记录日志,请省略斜杠(通常称为cron.log)
To put the log relative to a Rails app, omit the leading slash (and typically call it cron.log)
set :output, "log/cron.log"
要将日志放入特定的标准目录中:
To put the log in a specific fully-qualified directory:
set :output, '/abc/def/ghi/log/cron.log'
Theeverever Wiki提供了一些有关重定向输出的很好的示例:
The Whenever wiki has some good examples about redirecting output:
https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs
示例:
every 3.hours do
runner "MyModel.some_process", :output => 'cron.log'
rake "my:rake:task", :output => {:error => 'error.log', :standard => 'cron.log'}
command "/usr/bin/cmd"
end
这篇关于每当gem:我设置:output,但日志文件没有显示在我期望的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!