diff --git a/CHANGELOG.md b/CHANGELOG.md index fca4372..29a5398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,20 @@ # Changelog for the JSON Rails Logger gem +## 0.2.2 - 2021-03-02 (Bogdan) + +- `timestamp` renamed to `ts` in returning JSON +- Date format for timestamp changed to `%Y-%m-%dT%H:%M:%S.%3NZ` +- `request_id` is no longer internally generated if the header is missing from + the request, but the field will be missing from the returning JSON instead + ## 0.2.1 - 2021-02-23 (Bogdan) - Unit tests should now autorun on push and pull_request actions -- 'x-request-id' renamed to 'request_id' in code and returning JSON +- `x-request-id` renamed to `request_id` in code and returning JSON ## 0.2.0 - 2021-02-01 (Bogdan) -- Platform related fields are now grouped together inside the 'rails' field +- Platform related fields are now grouped together inside the `rails` field - Request ID is now present in every log message - MIT license file added to the repo - Added readme file with usage instructions diff --git a/Gemfile.lock b/Gemfile.lock index 5f64d7e..d6a0517 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - json_rails_logger (0.2.1) + json_rails_logger (0.2.2) json lograge railties diff --git a/lib/json_rails_logger/json_formatter.rb b/lib/json_rails_logger/json_formatter.rb index 46aa837..1c33add 100644 --- a/lib/json_rails_logger/json_formatter.rb +++ b/lib/json_rails_logger/json_formatter.rb @@ -14,7 +14,7 @@ def call(severity, timestamp, _progname, raw_msg) new_msg = format_message(msg) payload = { level: sev, - timestamp: timestp } + ts: timestp } payload.merge!(request_id.to_h) payload.merge!(new_msg.to_h) @@ -29,7 +29,7 @@ def process_severity(severity) end def process_timestamp(timestamp) - format_datetime(timestamp) + format_datetime(timestamp.utc) end def request_id diff --git a/lib/json_rails_logger/logger.rb b/lib/json_rails_logger/logger.rb index 42ff580..3091cb5 100644 --- a/lib/json_rails_logger/logger.rb +++ b/lib/json_rails_logger/logger.rb @@ -9,7 +9,7 @@ class Logger < ::Logger # binmode: false, shift_period_suffix: '%Y%m%d' def initialize(*args) @formatter = JsonRailsLogger::JsonFormatter.new - @formatter.datetime_format = '%Y-%m-%d %H:%M:%S' + @formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%3NZ' super(*args, formatter: @formatter) end diff --git a/lib/json_rails_logger/request_id_middleware.rb b/lib/json_rails_logger/request_id_middleware.rb index c18c92b..61114dc 100644 --- a/lib/json_rails_logger/request_id_middleware.rb +++ b/lib/json_rails_logger/request_id_middleware.rb @@ -11,7 +11,7 @@ def initialize(app) end def call(env) - request_id = env['action_dispatch.request_id'] + request_id = env['HTTP_X_REQUEST_ID'] Thread.current[JsonRailsLogger::REQUEST_ID] = request_id @app.call(env) ensure diff --git a/lib/json_rails_logger/version.rb b/lib/json_rails_logger/version.rb index 71ee29e..f8c6321 100644 --- a/lib/json_rails_logger/version.rb +++ b/lib/json_rails_logger/version.rb @@ -3,6 +3,6 @@ module JsonRailsLogger MAJOR = 0 MINOR = 2 - FIX = 1 + FIX = 2 VERSION = "#{MAJOR}.#{MINOR}.#{FIX}" end diff --git a/test/formatter_test.rb b/test/formatter_test.rb index f11740a..269993a 100644 --- a/test/formatter_test.rb +++ b/test/formatter_test.rb @@ -7,11 +7,11 @@ describe 'JsonRailsLogger::JsonFormatter' do # rubocop:disable Metrics/BlockLength let(:fixture) do formatter = JsonRailsLogger::JsonFormatter.new - formatter.datetime_format = '%Y-%m-%d %H:%M:%S' + formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%3NZ' formatter end - let(:timestamp) { DateTime.parse('2020-12-15T20:15:21') } + let(:timestamp) { Time.parse('2020-12-15 20:15:21.286') } let(:progname) { 'progname' } it 'should replace FATAL with ERROR for severity' do @@ -63,7 +63,7 @@ _(log_output).must_be_kind_of(String) json_output = JSON.parse(log_output) - _(json_output['timestamp']).must_equal('2020-12-15 20:15:21') + _(json_output['ts']).must_equal('2020-12-15T20:15:21.286Z') end it 'should move json to top level if message is json object' do