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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog for the JSON Rails Logger gem

## 2.2.0 - 2025-09

- Enhanced status and request type parsing logic
- Added handling to skip formatting when optional data missing
- Included checks for log message prefixes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the change log have a link to a gh ticket or is there no project board for this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DanielCouzens -

Because this gem is used on multiple applications and this update, while initiated via the catalog lift & shift, is not specific to that app and will benefit all applications using the gem.

Once the updated gem has been published I will link to the ticket that prompted the updates in that repo.

Hope that makes sense!

- Added debug log statements (commented out) for easier tracing

## 2.1.0 - 2025-09

- Updated ruby version and dependency versions to latest compatible releases
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GIT
PATH
remote: .
specs:
json_rails_logger (2.1.0)
json_rails_logger (2.2.0)
json
lograge
railties
Expand Down
21 changes: 16 additions & 5 deletions lib/json_rails_logger/json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def process_optional_messages(msg) # rubocop:disable Metrics/AbcSize
tmp_msg.insert(tmp_msg.index(','), format(' to %s', msg[:optional]['request_uri']))
end

tmp_msg
tmp_msg if OPTIONAL_KEYS.any? { |key| msg[:optional].key?(key) }
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down Expand Up @@ -248,25 +248,36 @@ def normalize_message(raw_msg)
end

def status_message?(msg)
# puts "Checking for status message in: #{msg}" if Rails.logger.debug?
msg.is_a?(String) &&
msg.downcase.match(/status [0-9]+/)
end

def status_message(msg)
status = msg.split[1]
# puts "Found status message in: #{msg}" if Rails.logger.debug?
split_status = msg.split
# puts "Split status message: #{split_status}" if Rails.logger.debug?
is_status = split_status[0] == 'response:'
code = split_status[is_status ? 2 : 1]

status = code.to_i

{ status: status }
end

def request_type?(msg)
# puts "Checking for request type in: #{msg}" if Rails.logger.debug?
msg.is_a?(String) &&
REQUEST_METHODS.any? { |method| msg.match(/#{method} http\S+/) }
end

def request_type(msg)
splitted_msg = msg.split
method = splitted_msg[0]
path = splitted_msg[1]
# puts "Found request type in: #{msg}" if Rails.logger.debug?
split_type = msg.split
# puts "Split type: #{split_type}" if Rails.logger.debug?
is_request = split_type[0] == 'request:'
method = split_type[is_request ? 1 : 0]
path = split_type[is_request ? 2 : 1]
{ method: method, path: path }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/json_rails_logger/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JsonRailsLogger
MAJOR = 2
MINOR = 1
MINOR = 2
PATCH = 0
SUFFIX = nil
VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}#{SUFFIX && "-#{SUFFIX}"}".freeze
Expand Down
2 changes: 1 addition & 1 deletion test/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_(log_output).must_be_kind_of(String)

json_output = JSON.parse(log_output)
_(json_output['status']).must_equal('200')
_(json_output['status']).must_equal(200)
end

it 'should parse method and path for requests' do
Expand Down