From 570ace34564447100ded79473c1ad145df8f06df Mon Sep 17 00:00:00 2001 From: Joseph Kotanchik Date: Mon, 18 Sep 2023 13:46:00 -0400 Subject: [PATCH] Tag log entries with the request ID. Tag create/update log entries with the submitter's harp id. --- app/controllers/measures_controller.rb | 32 +++++++++++++++----------- config/application.rb | 9 ++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/controllers/measures_controller.rb b/app/controllers/measures_controller.rb index 4ee920ddc..25c9f51bb 100644 --- a/app/controllers/measures_controller.rb +++ b/app/controllers/measures_controller.rb @@ -128,20 +128,24 @@ def measurement_period private def persist_measure(uploaded_file, permitted_params, user) - measures, main_hqmf_set_id = - if permitted_params[:hqmf_set_id].present? - update_measure(uploaded_file: uploaded_file, - target_id: permitted_params[:hqmf_set_id], - value_set_loader: build_vs_loader(permitted_params, false), - user: user) - else - create_measure(uploaded_file: uploaded_file, - measure_details: retrieve_measure_details(permitted_params), - value_set_loader: build_vs_loader(permitted_params, false), - user: user) - end - check_measures_for_unsupported_data_elements(measures) - return measures, main_hqmf_set_id + logger.tagged(user.harp_id ? user.harp_id : "unknown user") do + measures, main_hqmf_set_id = + if permitted_params[:hqmf_set_id].present? + logger.info("update") + update_measure(uploaded_file: uploaded_file, + target_id: permitted_params[:hqmf_set_id], + value_set_loader: build_vs_loader(permitted_params, false), + user: user) + else + logger.info("create") + create_measure(uploaded_file: uploaded_file, + measure_details: retrieve_measure_details(permitted_params), + value_set_loader: build_vs_loader(permitted_params, false), + user: user) + end + check_measures_for_unsupported_data_elements(measures) + return measures, main_hqmf_set_id + end end def check_measures_for_unsupported_data_elements(measures) diff --git a/config/application.rb b/config/application.rb index b07261501..1cf64529e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,11 +40,13 @@ class Application < Rails::Application # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" - Rails.logger = Logger.new(STDOUT) - Rails.logger.formatter = proc do |severity, datetime, progname, msg| + # Configure log formatter + logger = Logger.new(STDOUT) + logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") "#{date_format} [#{severity}] - #{msg}'\n" end + Rails.logger = ActiveSupport::TaggedLogging.new(logger) config.log_level = :info @@ -53,6 +55,9 @@ class Application < Rails::Application config.filter_parameters += [:vsac_api_key] config.filter_parameters += [:api_key] + # Configure log tags that will apply to all log entries + config.log_tags = [:request_id] + # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true