Skip to content

Commit

Permalink
Merge pull request #47 from DFE-Digital/stop-logging
Browse files Browse the repository at this point in the history
Change ActiveJob log level
  • Loading branch information
duncanjbrown authored Sep 21, 2022
2 parents 2cd7cd3 + c27c002 commit 1ec7b35
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/dfe/analytics/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class Railtie < Rails::Railtie
app.config.middleware.use DfE::Analytics::Middleware::RequestIdentity
end

initializer 'dfe.analytics.logger' do
ActiveSupport.on_load(:active_job) do
analytics_job = DfE::Analytics::AnalyticsJob
# Rails < 6.1 doesn't support log_arguments = false so we only log warn
# to prevent wild log inflation
if analytics_job.respond_to?(:log_arguments=)
analytics_job.log_arguments = false
else
analytics_job.logger = ::Rails.logger.dup.tap { |l| l.level = Logger::WARN }
end
end
end

config.after_initialize do
# internal gem tests will sometimes suppress this so they can test the
# init process
Expand Down
1 change: 1 addition & 0 deletions lib/dfe/analytics/send_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.do(events)

def perform(events)
if DfE::Analytics.log_only?
# Use the Rails logger here as the job's logger is set to :warn by default
Rails.logger.info("DfE::Analytics: #{events.inspect}")
else
response = DfE::Analytics.events_client.insert(events, ignore_unknown: true)
Expand Down
4 changes: 0 additions & 4 deletions lib/generators/dfe/analytics/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def config_options
DESC
end
end

# def self.banner(command, namespace = nil, subcommand = false)
# "#{basename} #{subcommand_prefix} #{command.usage}"
# end
end
end
end

0 comments on commit 1ec7b35

Please sign in to comment.