4

I try to move all the logging of my rails (3.2.17) app in production and staging to papertrail. Now I'm trying to set the logger for sidekiq in config/initializers/sidekiq.rb like this:

Sidekiq.configure_server do |config|
  Sidekiq::Logging.logger = RemoteSyslogLogger.new('logs.papertrailapp.com', ENV.fetch('PAPERTRAIL_PORT'), program: "sidekiq-#{Rails.env}")
end

When I try to start sidekiq with:

bundle exec sidekiq --index 0 --pidfile <PATH_TO_PID> --environment staging --daemon

I get

You really should set a logfile if you're going to daemonize
...bundle/ruby/2.0.0/gems/sidekiq-2.17.4/lib/sidekiq/cli.rb:141:in `daemonize'
...bundle/ruby/2.0.0/gems/sidekiq-2.17.4/lib/sidekiq/cli.rb:39:in `parse'
...bundle/ruby/2.0.0/gems/sidekiq-2.17.4/bin/sidekiq:7:in `<top (required)>'
...bundle/ruby/2.0.0/bin/sidekiq:23:in `load'
...bundle/ruby/2.0.0/bin/sidekiq:23:in `<main>'

However if I give sidekiq a dummy for logging first:

bundle exec sidekiq --index 0 --pidfile <PATH_TO_PID> --environment staging --daemon --logfile /dev/null

it works like a charm (logs are sent to papertrail), since the initializer seems to override the previous option.

But I find this approach quite ugly. Anybody got a cleaner approach to this?

Benjamin
  • 1,726
  • 1
  • 14
  • 35
  • Does this [link](http://stackoverflow.com/questions/20058417/sidekiq-server-not-loading-configuration-file) help you? – Rajesh Omanakuttan Apr 10 '14 at 13:20
  • Not really, in that case a config file was used. I need to use (at least I don't see another option) an initializer to make it work with papertrail. – Benjamin Apr 11 '14 at 07:41

1 Answers1

0

I discussed it with the owner of sidekiq and he made a good point: from the time the process is started until the time the initializer has run, a lot of things can go wrong. If the logger is only initialized in the initializer, everything that happended before, won't appear in any log.

I probably will go with the appoach recommended by the sidekiq owner:

bundle exec sidekiq | logger -t sidekiq
Benjamin
  • 1,726
  • 1
  • 14
  • 35