Skip to content

Commit

Permalink
fix: Refactor message generation logic
Browse files Browse the repository at this point in the history
- Updated the method to accept a hash of fields.
- Added a check for required message input.
- Improved handling of source and timer in the log message.
- Cleaned up parameter documentation format.
  • Loading branch information
jonrandahl committed Feb 17, 2025
1 parent 410b087 commit 87fde11
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/data_services_api/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,20 @@ def log_message(log_fields, log_type = 'info')

# Construct the message based on the properties received and return the formatted message
# @param [String] msg - The initial message to log
# @param [String] source - The source of the request
# @param [Float] timer - The time it took to process the request
# @param [String] _path - The path of the request
# @param [String] _query_string - The query string of the request
# @param [String] [source] - The source of the request
# @param [Float] [timer] - The time it took to process the request
# @param [String] [path] - The path of the request
# @param [String] [query_string] - The query string of the request
# @return [String] - The formatted message
# TODO: Agree on the format of the log message and the fields to be included in the message
def generate_service_message(msg: '', source: '', timer: 0, _path: '', _query_string: '')
# msg += " for #{path}" if _path.present?
# msg += "?#{query_string}" if _query_string.present?
def generate_service_message(fields)
raise ServiceException.new('Message is required', 400) unless fields[:msg]

msg = fields[:msg]
source = fields[:source]
timer = fields[:timer]
# TODO: Agree on the format and fields to be included in the log message
# msg += " for #{path}" if in_rails? && fields[:path].present?
# msg += "?#{query_string}" if in_rails? && fields[:query_string].present?
msg += " from the #{source.upcase} service" if in_rails? && source.present?
msg += " for #{format('%.0f ms', timer)}" if timer.positive?
msg
Expand Down

0 comments on commit 87fde11

Please sign in to comment.