Can't get logging to work. #48

Closed
opened 2025-12-29 00:21:55 +01:00 by adam · 2 comments
Owner

Originally created by @minimul on GitHub (Aug 11, 2017).

I am running a rake task within config/cronotab.rb e.g.

# config/cronotab.rb
require 'rake'

Rails.app_class.load_tasks

class QboRenewTokens
  def perform
    Rake::Task['quickbooks:renew_oauth2_tokens'].invoke
   end
end

Crono.perform(QboRenewTokens).with_options(truncate_log: 100).every 5.minutes

Within the rake task I have both Rails.logger and p commands

If I run the task via command line bin/rake quickbooks:renew_oauth2_token I see the output in the console and in the log/development.log.

I am running crono as a daemon but none of my logger output shows up in log/crono.log nor log/development.log.

This is all that is recorded in log/crono.log

I, [2017-08-11T08:22:44.237388 #3867]  INFO -- : Perform QboRenewTokens
I, [2017-08-11T08:22:44.238103 #3867]  INFO -- : Finished QboRenewTokens in 0.00 seconds
I, [2017-08-11T08:27:44.237794 #3867]  INFO -- : Perform QboRenewTokens
I, [2017-08-11T08:27:44.238448 #3867]  INFO -- : Finished QboRenewTokens in 0.00 seconds
Originally created by @minimul on GitHub (Aug 11, 2017). I am running a rake task within `config/cronotab.rb` e.g. ```ruby # config/cronotab.rb require 'rake' Rails.app_class.load_tasks class QboRenewTokens def perform Rake::Task['quickbooks:renew_oauth2_tokens'].invoke end end Crono.perform(QboRenewTokens).with_options(truncate_log: 100).every 5.minutes ``` Within the rake task I have both `Rails.logger` and `p` commands If I run the task via command line `bin/rake quickbooks:renew_oauth2_token` I see the output in the console and in the `log/development.log`. I am running crono as a daemon but none of my logger output shows up in `log/crono.log` nor `log/development.log`. This is all that is recorded in `log/crono.log` ``` I, [2017-08-11T08:22:44.237388 #3867] INFO -- : Perform QboRenewTokens I, [2017-08-11T08:22:44.238103 #3867] INFO -- : Finished QboRenewTokens in 0.00 seconds I, [2017-08-11T08:27:44.237794 #3867] INFO -- : Perform QboRenewTokens I, [2017-08-11T08:27:44.238448 #3867] INFO -- : Finished QboRenewTokens in 0.00 seconds ```
adam closed this issue 2025-12-29 00:21:55 +01:00
Author
Owner

@minimul commented on GitHub (Aug 12, 2017):

Solution: Use Crono.logger.(info|warn|error) instead of Rails.logger.*

@minimul commented on GitHub (Aug 12, 2017): Solution: Use `Crono.logger.(info|warn|error)` instead of `Rails.logger.*`
Author
Owner

@firrib commented on GitHub (Aug 31, 2020):

To limit/control the output to the log file, in the perform function, I used: Crono.logger.level=:warn, using the appropriate log level defined in section 2.2 of https://guides.rubyonrails.org/debugging_rails_applications.html.
The Crono::Logging is a standard Ruby logging wrapper. If there is a better place to put this code (or even this reply), then please let me know. Thanks for documenting this, minimul, and for this gem, plashchynski. It's very helpful.

@firrib commented on GitHub (Aug 31, 2020): To limit/control the output to the log file, in the `perform` function, I used: `Crono.logger.level=:warn`, using the appropriate log level defined in section 2.2 of https://guides.rubyonrails.org/debugging_rails_applications.html. The Crono::Logging is a standard Ruby logging wrapper. If there is a better place to put this code (or even this reply), then please let me know. Thanks for documenting this, `minimul`, and for this gem, `plashchynski`. It's very helpful.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/crono#48