Skip to content

Commit

Permalink
Merge pull request #19 from epimorphics/spike/improved_log_message_ha…
Browse files Browse the repository at this point in the history
…ndling

Spike: Improved log message handling
  • Loading branch information
jonrandahl authored Feb 24, 2025
2 parents ec3469f + 8b716e9 commit 0ff6aa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.5.2 - 2025-02

- (Jon) Included the HTTP method in the response log.
- (Jon) Set a default method value of 'GET' if not provided.
- (Jon) Ensured logs are sorted and cleaned up before final output.
- (Jon) Updated the instrumenter calls to include exceptions as a keyword
argument for better clarity and consistency.
[GH-465](https://github.com/epimorphics/ukhpi/issues/465)
Expand Down
4 changes: 4 additions & 0 deletions lib/data_services_api/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_json(http_url, params, options) # rubocop:disable Metrics/MethodLength,
source: URI.parse(http_url).path.split('/').last,
timer: elapsed_time
}),
method: response.env.method.upcase,
path: URI.parse(http_url).path,
query_string: query_string,
request_status: 'processing',
Expand Down Expand Up @@ -262,13 +263,16 @@ def log_message(log_fields, log_type = 'info')
duration = (end_time - start_time) / 1000 if start_time
# parse out the optional parameters and set defaults
log_fields[:message] ||= log_fields[:response]&.body
log_fields[:method] ||= 'GET'
log_fields[:request_time] ||= duration
log_fields[:request_status] ||= 'completed' if log_fields[:status] == 200
log_fields[:start_time] = nil
log_fields[:status] ||= 200

# Clear out nil values from the log fields
logs = log_fields.compact

logs.sort.to_h
# Log the API responses at the appropriate level requested
case log_type
when 'error'
Expand Down

0 comments on commit 0ff6aa6

Please sign in to comment.