Skip to content
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
4 changes: 0 additions & 4 deletions app/jobs/reports/base_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def save_report(report_name, body, extension:)
upload_file_to_s3_timestamped_and_latest(report_name, body, extension)
end

def reports_logger
@reports_logger ||= ActiveSupport::Logger.new(Rails.root.join('log', 'reports.log'))
end

def upload_file_to_s3_timestamped_and_latest(report_name, body, extension)
latest_path, path = generate_s3_paths(report_name, extension)
content_type = Mime::Type.lookup_by_extension(extension).to_s
Expand Down
10 changes: 3 additions & 7 deletions app/services/encryption/kms_logger.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
module Encryption
class KmsLogger
LOG_FILENAME = 'kms.log'
def self.log(action, key_id:, context: nil)
output = {
kms: {
action: action,
encryption_context: context,
key_id: key_id,
},
log_filename: LOG_FILENAME,
log_filename: Idp::Constants::KMS_LOG_FILENAME,
}

logger.info(output.to_json)
end

def self.logger
@logger ||= if FeatureManagement.log_to_stdout?
Logger.new(STDOUT)
else
Logger.new(Rails.root.join('log', LOG_FILENAME))
end
Rails.application.config.kms_logger
end
end
end
25 changes: 24 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

require_relative '../lib/asset_sources'
require_relative '../lib/identity_config'
require_relative '../lib/feature_management'
require_relative '../lib/fingerprinter'
require_relative '../lib/identity_job_log_subscriber'
require_relative '../lib/email_delivery_observer'
Expand Down Expand Up @@ -59,9 +60,31 @@ class Application < Rails::Application
config.active_job.queue_adapter = :good_job

FileUtils.mkdir_p(Rails.root.join('log'))
config.active_job.logger = ActiveSupport::Logger.new(Rails.root.join('log', 'workers.log'))
config.active_job.logger = if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(
Rails.root.join('log', Idp::Constants::WORKER_LOG_FILENAME),
)
end
config.active_job.logger.formatter = config.log_formatter

config.logger = if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(
Rails.root.join('log', "#{Rails.env}.log"),
)
end

config.kms_logger = if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(
Rails.root.join('log', Idp::Constants::KMS_LOG_FILENAME),
)
end

config.good_job.execution_mode = :external
config.good_job.poll_interval = 5
config.good_job.enable_cron = true
Expand Down
4 changes: 0 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
# creates false positive results.
config.action_dispatch.ip_spoofing_check = false

if IdentityConfig.store.log_to_stdout
Rails.logger = Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new(STDOUT)
end
config.log_level = :info
config.lograge.ignore_actions = ['Api::Internal::SessionsController#show']
end
41 changes: 15 additions & 26 deletions config/initializers/ahoy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

require 'utf8_cleaner'

Rails.application.configure do
config.ahoy = ActiveSupport::OrderedOptions.new
config.ahoy.event_logger = if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(
Rails.root.join('log', Idp::Constants::EVENT_LOG_FILENAME),
)
end
end

Ahoy.api = false
# Period of inactivity before a new visit is created
Ahoy.visit_duration = IdentityConfig.store.session_timeout_in_minutes.minutes
Expand All @@ -12,18 +23,16 @@

module Ahoy
class Store < Ahoy::BaseStore
EVENT_FILENAME = 'events.log'

def track_visit(data)
log_visit(data)
def track_visit(_data)
nil
end

def track_event(data)
data.delete(:user_id)
data[:id] = data.delete(:event_id)
data[:visitor_id] = ahoy.visitor_token
data[:visit_id] = data.delete(:visit_token)
data[:log_filename] = EVENT_FILENAME
data[:log_filename] = Idp::Constants::EVENT_LOG_FILENAME

log_event(data)
end
Expand All @@ -40,28 +49,8 @@ def exclude?

protected

def log_visit(data)
visit_logger.info data.to_json
end

def log_event(data)
event_logger.info data.to_json
end

def visit_logger
@visit_logger ||= if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(Rails.root.join('log', 'visits.log'))
end
end

def event_logger
@event_logger ||= if FeatureManagement.log_to_stdout?
ActiveSupport::Logger.new(STDOUT)
else
ActiveSupport::Logger.new(Rails.root.join('log', EVENT_FILENAME))
end
Rails.application.config.ahoy.event_logger.info(data.to_json)
end

def invalid_uuid?(token)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
http_read_timeout: IdentityConfig.store.aws_http_timeout.to_f,
retry_limit: IdentityConfig.store.aws_http_retry_limit,
retry_max_delay: IdentityConfig.store.aws_http_retry_max_delay,
logger: ActiveSupport::Logger.new(Rails.root.join('log', 'production.log')),
logger: Rails.application.config.logger,
log_formatter: log_formatter,
)
7 changes: 5 additions & 2 deletions config/initializers/telephony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
Telephony.config do |c|
c.adapter = IdentityConfig.store.telephony_adapter.to_sym
c.logger = if FeatureManagement.log_to_stdout?
Logger.new(STDOUT, level: :info)
ActiveSupport::Logger.new(STDOUT, level: :info)
else
Logger.new('log/telephony.log', level: :info)
ActiveSupport::Logger.new(
Rails.root.join('log', Idp::Constants::TELEPHONY_LOG_FILENAME),
level: :info,
)
end

c.voice_pause_time = IdentityConfig.store.voice_otp_pause_time
Expand Down
12 changes: 2 additions & 10 deletions lib/identity_job_log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'active_job/log_subscriber'

class IdentityJobLogSubscriber < ActiveSupport::LogSubscriber
LOG_FILENAME = 'workers.log'

def enqueue(event)
job = event.payload[:job]
ex = event.payload[:exception_object]
Expand Down Expand Up @@ -122,13 +120,7 @@ def logger
end

def self.worker_logger
return @worker_logger if defined?(@worker_logger)

if FeatureManagement.log_to_stdout?
@worker_logger = ActiveSupport::Logger.new(STDOUT)
else
@worker_logger = ActiveSupport::Logger.new(Rails.root.join('log', LOG_FILENAME))
end
Rails.application.config.active_job.logger
end

private
Expand Down Expand Up @@ -175,7 +167,7 @@ def default_attributes(event, job)
trace_id: trace_id(job),
queue_name: queue_name(event),
job_id: job.job_id,
log_filename: LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
}
end

Expand Down
6 changes: 6 additions & 0 deletions lib/idp/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ module Idp
module Constants
AVAILABLE_LOCALES = %w[en es fr]
UUID_REGEX = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/

KMS_LOG_FILENAME = 'kms.log'
WORKER_LOG_FILENAME = 'workers.log'
EVENT_LOG_FILENAME = 'events.log'
TELEPHONY_LOG_FILENAME = 'telephony.log'

module Vendors
ACUANT = 'acuant'
LEXIS_NEXIS = 'lexis_nexis'
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/identity_job_log_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
queue_name: kind_of(String),
timestamp: kind_of(String),
trace_id: nil,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -164,7 +164,7 @@
queue_name: kind_of(String),
timestamp: kind_of(String),
trace_id: nil,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -200,7 +200,7 @@
queue_name: 'NilClass(low)',
timestamp: kind_of(String),
trace_id: nil,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -235,7 +235,7 @@
trace_id: nil,
queue_name: 'NilClass(low)',
job_id: job.job_id,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -300,7 +300,7 @@
queue_name: kind_of(String),
timestamp: kind_of(String),
trace_id: nil,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -357,7 +357,7 @@ def perform(_); end
queue_name: 'NilClass(low)',
timestamp: kind_of(String),
trace_id: nil,
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -393,7 +393,7 @@ def perform(_); end
queue_name: 'NilClass(low)',
job_id: job.job_id,
scheduled_at: kind_of(String),
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down Expand Up @@ -435,7 +435,7 @@ def perform(_); end
queue_name: kind_of(String),
job_id: job.job_id,
exception_class_warn: 'Errno::ECONNREFUSED',
log_filename: IdentityJobLogSubscriber::LOG_FILENAME,
log_filename: Idp::Constants::WORKER_LOG_FILENAME,
)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/services/encryption/kms_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
encryption_context: { context: 'pii-encryption', user_uuid: '1234-abc' },
key_id: 'super-duper-aws-kms-key-id',
},
log_filename: Encryption::KmsLogger::LOG_FILENAME,
log_filename: Idp::Constants::KMS_LOG_FILENAME,
}.to_json

expect(described_class.logger).to receive(:info).with(log)
Expand All @@ -31,7 +31,7 @@
encryption_context: nil,
key_id: 'super-duper-aws-kms-key-id',
},
log_filename: Encryption::KmsLogger::LOG_FILENAME,
log_filename: Idp::Constants::KMS_LOG_FILENAME,
}.to_json

expect(described_class.logger).to receive(:info).with(log)
Expand Down