Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

sidekiq の ログの日付を日本標準時に変更する

More than 5 years have passed since last update.

sidekiq のログフォーマットのカスタマイズ方法が github に記載されている。
完全に独自のフォーマットで出力したい場合には適当に MyFormatter を作ればよいが、日付の部分だけ変更したい場合には次のようにすれば良さそう。

config/initializers/sidekiq.rb
class MySidekiqFormatter < Sidekiq::Logging::WithoutTimestamp
  def call(severity, time, program_name, message)
    "#{time.localtime.iso8601(3)} #{super}"
  end
end

Sidekiq.configure_server do |config|
  Sidekiq::Logging.logger.formatter = MySidekiqFormatter.new
  config.redis = { url: 'redis://localhost:6379/0', namespace: "sidekiq_#{Rails.env}" }
end

Sidekiq.configure_client do |config|
  Sidekiq::Logging.logger.formatter = MySidekiqFormatter.new
  config.redis = { url: 'redis://localhost:6379/0', namespace: "sidekiq_#{Rails.env}" }
end

Sidekiq::Logging::WithoutTimestamp は sidekiq の lib/sidekiq/logging.rb を参照。

h_hys
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away