Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 337 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Log inside Sidekiq worker

#1
I'm trying to log the progress of my sideqik worker using `tail -f log/development.log` in development and `heroku logs` in production.

However, everything inside the worker and everything called by the worker does not get logged. In the code below, only TEST 1 gets logged.

How can I log everything inside the worker and the classes the worker calls?

# app/controllers/TasksController.rb
def import_data
Rails.logger.info "TEST 1" # shows up in development.log
DataImportWorker.perform_async
render "done"
end

# app/workers/DataImportWorker.rb
class DataImportWorker
include Sidekiq::Worker

def perform
Rails.logger.info "TEST 2" # does not show up in development.log

importer = Importer.new
importer.import_data
end
end


# app/controllers/services/Importer.rb
class Importer
def import_data
Rails.logger.info "TEST 3" # does not show up in development.log
end
end

**Update**

I still don't understand why `Rails.logger.info` or `Sidekiq.logger.info` don't log into the log stream. Got it working by replacing `Rails.logger.info` with `puts`.
Reply

#2
I've found this solution [here][1], it seems to work well.

Sidekiq uses the Ruby Logger class with default Log Level as `INFO`, and its settings are independent from Rails.

You may set the Sidekiq Log Level for the `Logger` used by Sidekiq in `config/initializers/sidekiq.rb`:


```ruby
Sidekiq.configure_server do |config|
config.logger.level = Rails.logger.level
end
```


[1]:

[To see links please register here]

Reply

#3
It works in rails 6:

# config/initializers/sidekiq.rb

Rails.logger = Sidekiq.logger
ActiveRecord::Base.logger = Sidekiq.logger
Reply

#4
There is a `Sidekiq.logger` and simply `logger` reference that you can use within your workers. The default should be to STDOUT and you should just direct your output in production to the log file path of your choice.
Reply

#5
@migu, have you tried the below command in the `config/initializer.rb` ?

Rails.logger = Sidekiq::Logging.logger
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through