Skip to content

Commit

Permalink
Merge pull request #24 from epimorphics/dev
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
bogdanadrianmarc authored Mar 9, 2021
2 parents cb0b9b9 + 0f304f1 commit a911a71
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
json_rails_logger (0.2.1)
json_rails_logger (0.2.2)
json
lograge
railties
Expand Down
4 changes: 2 additions & 2 deletions lib/json_rails_logger/json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,7 +29,7 @@ def process_severity(severity)
end

def process_timestamp(timestamp)
format_datetime(timestamp)
format_datetime(timestamp.utc)
end

def request_id
Expand Down
2 changes: 1 addition & 1 deletion lib/json_rails_logger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/json_rails_logger/request_id_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -3,6 +3,6 @@
module JsonRailsLogger
MAJOR = 0
MINOR = 2
FIX = 1
FIX = 2
VERSION = "#{MAJOR}.#{MINOR}.#{FIX}"
end
6 changes: 3 additions & 3 deletions test/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a911a71

Please sign in to comment.