Skip to content

Commit

Permalink
Remove logger overrides from Gouda
Browse files Browse the repository at this point in the history
In our app, this causes more trouble than it is worth - Gouda should use the common Rails logger and not touch it. If we want to log less SQL from the Gouda worker, we should look for a different way to do so - for example, by selectively silencing the logger using blocks or by temporarily lowering the logging level during the query.
  • Loading branch information
julik committed Jul 3, 2024
1 parent d3e0195 commit af416b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
24 changes: 14 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
## [Unreleased]

## [0.1.0] - 2023-06-10
## [0.1.0] - 2024-06-10

- Initial release

## [0.1.1] - 2023-06-10
## [0.1.1] - 2024-06-10

- Fix support for older ruby versions until 2.7

## [0.1.2] - 2023-06-11
## [0.1.2] - 2024-06-11

- Updated readme and method renaming in Scheduler

## [0.1.3] - 2023-06-11
## [0.1.3] - 2024-06-11

- Allow the Rails app to boot even if there is no database yet

## [0.1.4] - 2023-06-14
## [0.1.4] - 2024-06-14

- Rescue NoDatabaseError at scheduler update.
- Include tests in gem, for sake of easier debugging.
- Reduce logging in local test runs.
- Bump local ruby version to 3.3.3

## [0.1.5] - 2023-06-18
## [0.1.5] - 2024-06-18

- Update documentation
- Don't pass on scheduler keys to retries

## [0.1.6] - 2023-06-18
## [0.1.6] - 2024-06-18

- Fix: don't upsert workloads twice when starting Gouda.
- Add back in Appsignal calls

## [0.1.7] - 2023-06-21
## [0.1.7] - 2024-06-21

- Separate all instrumentation to use ActiveSupport::Notification

## [0.1.8] - 2023-06-21
## [0.1.8] - 2024-06-21

- Move some missed instrumentations to Gouda.instrument

## [0.1.9] - 2023-06-26
## [0.1.9] - 2024-06-26

- Fix: cleanup_preserved_jobs_before in Gouda::Workload.prune now points to Gouda.config

## [0.1.10] - 2024-07-03

- Fix: remove logger overrides that Gouda should install, as this causes problems for Rails apps hosting Gouda
40 changes: 25 additions & 15 deletions lib/gouda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ class Gouda::Configuration
config_accessor(:cleanup_preserved_jobs_before, default: 3.hours)
config_accessor(:polling_sleep_interval_seconds, default: 0.2)
config_accessor(:worker_thread_count, default: 1)
config_accessor(:logger, default: ActiveSupport::Logger.new($stdout))
config_accessor(:app_executor)
config_accessor(:cron, default: {})
config_accessor(:enable_cron, default: true)
# Log levels are:
# constant | level
# Logger::DEBUG (0)
# Logger::INFO (1)
# Logger::WARN (2)
# Logger::ERROR (3)
# Logger::FATAL (4)
# Logger::UNKNOWN (5)
config_accessor(:log_level, default: Logger::DEBUG)
# Deprecated logger configuration. This needs to be available in the
# Configuration object because it might be used from the Rails app
# that is using Gouda. The config values will be ignored though.
config_accessor(:logger, default: nil)
config_accessor(:log_level, default: nil)
end

class InterruptError < StandardError
Expand All @@ -52,10 +47,10 @@ def self.start
Gouda::AnyQueue
end

Gouda.logger.info("Gouda version: #{Gouda::VERSION}")
Gouda.logger.info("Worker threads: #{Gouda.config.worker_thread_count}")
logger.info("Gouda version: #{Gouda::VERSION}")
logger.info("Worker threads: #{Gouda.config.worker_thread_count}")

Gouda.worker_loop(n_threads: Gouda.config.worker_thread_count, queue_constraint: queue_constraint)
worker_loop(n_threads: Gouda.config.worker_thread_count, queue_constraint: queue_constraint)
end

def self.config
Expand All @@ -67,14 +62,29 @@ def self.configure
end

def self.logger
Gouda.config.logger
# By default, return a logger that sends data nowhere. The `Rails.logger` method
# only becomes available later in the Rails lifecycle.
@fallback_gouda_logger ||= begin
ActiveSupport::Logger.new($stdout).tap do |logger|
logger.level = Logger::WARN
end
end

# We want the Rails-configured loggers to take precedence over ours, since Gouda
# is just an ActiveJob adapter and the Workload is just an ActiveRecord, in the end.
# So it should be up to the developer of the app, not to us, to set the logger up
# and configure out. There are also gems such as "stackdriver" from Google which
# rather unceremonously overwrite the Rails logger with their own. If that happens,
# it is the choice of the user to do so - and we should honor that choice. Same for
# the logging level - the Rails logger level must take precendence. Same for logger
# broadcasts which get set up, for example, by the Rails console when you start it.
Rails.try(:logger) || ActiveJob::Base.try(:logger) || @fallback_gouda_logger
end

def self.instrument(channel, options, &block)
ActiveSupport::Notifications.instrument("#{channel}.gouda", options, &block)
end


def self.create_tables(active_record_schema)
active_record_schema.create_enum :gouda_workload_state, %w[enqueued executing finished]
active_record_schema.create_table :gouda_workloads, id: :uuid do |t|
Expand Down
3 changes: 1 addition & 2 deletions test/gouda/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def self.adapter
@adapter || Gouda::Adapter.new
@case_random = Random.new(Minitest.seed)
Gouda::Railtie.initializers.each(&:run)
ActiveJob::Base.logger = nil
Gouda.config.logger.level = 4
Gouda.logger.level = Logger::WARN
end

teardown do
Expand Down

0 comments on commit af416b7

Please sign in to comment.