-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from epimorphics/dev
Release 0.2.0
- Loading branch information
Showing
10 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog for the JSON Rails Logger gem | ||
|
||
## 0.2.0 - 2021-02-01 (Bogdan) | ||
|
||
- 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 | ||
|
||
## 0.1.0 - 2021-01-26 (Bogdan) | ||
|
||
- This is an initial release, contains a simple JSON Rails Logger | ||
with some customisation applied to it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
json_rails_logger (0.1.0) | ||
json_rails_logger (0.2.0) | ||
json | ||
lograge | ||
railties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Epimorphics Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# json-rails-logger | ||
A custom rails logger that outputs json instead of raw text | ||
|
||
A custom rails logger that outputs JSON instead of raw text. As an extra the | ||
logger also saves the `request_id` for any log message, in the returned JSON | ||
object. The formatter has a couple of changes that are down to preference, but | ||
these don't affect the functionality in any way. This gem can be used with any | ||
Rails app using the installation steps below. | ||
|
||
## Installation | ||
|
||
In your Rails app, add this to your gemfile:\ | ||
`gem 'json_rails_logger', git: '[email protected]:epimorphics/json-rails-logger.git'` | ||
|
||
And this to your environment config:\ | ||
`config.logger = JsonRailsLogger::Logger.new(STDOUT)` | ||
|
||
## Running the tests | ||
|
||
Tests are located in the `./test/` folder. | ||
|
||
After cloning the repo, first execute:\ | ||
`bundle install` | ||
|
||
To run the tests, use:\ | ||
`rake test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module JsonRailsLogger | ||
REQUEST_ID = :request_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'constants' | ||
|
||
module JsonRailsLogger | ||
# Middleware that saves the request_id into a constant | ||
# and clears it after usage in the formatter | ||
class RequestIdMiddleware | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
request_id = env['action_dispatch.request_id'] | ||
Thread.current[JsonRailsLogger::REQUEST_ID] = request_id | ||
@app.call(env) | ||
ensure | ||
Thread.current[JsonRailsLogger::REQUEST_ID] = nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
module JsonRailsLogger | ||
MAJOR = 0 | ||
MINOR = 1 | ||
MINOR = 2 | ||
FIX = 0 | ||
VERSION = "#{MAJOR}.#{MINOR}.#{FIX}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters