[英]ActiveJob + Sidekiq 6.0.3: How to write to a log file?
I'm using Sidekiq to get some background jobs done.我正在使用 Sidekiq 来完成一些后台工作。 I am also trying to log some messages from these jobs to a log file, but I have been unable to do this simple task.
我还尝试将这些作业中的一些消息记录到日志文件中,但我一直无法完成这个简单的任务。
Example of the kind of job I'm running我正在运行的工作类型示例
class TestJob < ApplicationJob
queue_as :default
def perform
text = 'Print me to a file!'
Rails.logger.error "Rails.logger.info : #{text}"
logger.error "logger.info : #{text}"
end
end
Running TestJob.perform_now
, in a controller action for example, works as expected, printing the messages to the server terminal output, as well as to logs/development.log
. TestJob.perform_now
,在控制器操作中运行TestJob.perform_now
按预期工作,将消息打印到服务器终端输出以及logs/development.log
。
But running TestJob.perform_later
doesn't print my messages.但是运行
TestJob.perform_later
不会打印我的消息。 Anywhere.任何地方。 Not to the Sidekiq terminal, the server terminal, log files, nothing.
不是Sidekiq终端,服务器终端,日志文件,什么都没有。
I tried redirecting the logs, as suggested in the Sidekiq Logging wiki .我尝试按照Sidekiq Logging wiki中的建议重定向日志。 But the messages didn't get printed there either.
但是消息也没有打印在那里。
I feel like I might be missing something crucial.我觉得我可能错过了一些关键的东西。
Try to call Sidekiq.logger
, as in:尝试调用
Sidekiq.logger
,如下所示:
Sidekiq.logger.error "logger.info : #{text}"
Putting "logger.info" in the log of an error might be a little weird, but I was just taking from the example posted in the question.将“logger.info”放在错误日志中可能有点奇怪,但我只是从问题中发布的示例中获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.