Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ActiveJob log level #47

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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