grape_logging 1.8.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9792108b8ff9d35fc3004f21fbf23ea8dc91f5ad94759c8ce03e9e2e24544cc
4
- data.tar.gz: c1994437d15c8fe42c543911757b89ddf799acd00baa6a8b7e9b97ba26af805a
3
+ metadata.gz: 3eae6798e8a0130a3825edab4719589e70fe49aa0f210003e9089db17a294f48
4
+ data.tar.gz: '0907410df65f7a7e782581aacd5ac1a0ab5e6a9a67111aa63eb627d73d5d174f'
5
5
  SHA512:
6
- metadata.gz: 760d3d7f0ea911e31ab5f43fb8fe3e030d8c8a295514990b6c66000e85a0e9ad302fe443f82d48d9e6f9458a8b92dcff74afe4af691048a5f390d7e8884cc200
7
- data.tar.gz: 39a06694b3fc24691efad563641e9664d84623793e06c3586d9e3e8e859c4b8db3d0c761c907620f78ac1ad6eebbddd1f40fb23512c315a8cbddea62ec0e7bcf
6
+ metadata.gz: 1a142c81ac1b47e22d960db29f7efe1b336f706f1e4c4dbbf5c019fca33c464ac6742d730046d45b933854ba53173ac884604bbfc7c8c18963bf2b74fbeabf52
7
+ data.tar.gz: c592ed9ea7d8d289b17297ec41f616a556bce9bd2d041ce738ed035155e789991789adc44610a1fec546fd00fdd2986fb93de5d04534f493ebc3b21e43001315
@@ -0,0 +1,23 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"]
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby-version }}
19
+ bundler-cache: true
20
+ - name: Install dependencies
21
+ run: bundle install
22
+ - name: Run tests
23
+ run: bundle exec rspec spec/
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .rspec
11
+ .idea/
data/CHANGELOG.md ADDED
@@ -0,0 +1,201 @@
1
+ # Changelog
2
+
3
+ ## [2.1.0] - 2025-07-09
4
+
5
+ ## Added
6
+ - [#91](https://github.com/aserafin/grape_logging/pull/91) Add ActionDispatch request ID to logger arguments hash as `:request_id` - [@samsonjs](https://github.com/samsonjs).
7
+
8
+ [2.1.0]: https://github.com/aserafin/grape_logging/compare/v2.0.0...v2.1.0
9
+
10
+ ## [2.0.0] - 2025-07-09
11
+
12
+ ### Changed
13
+ - **BREAKING**: Updated to support Grape 2.1 and Rack 3.1
14
+ - Minimum supported Ruby version is now 3.0
15
+ - Replaced Travis CI with GitHub Actions for continuous integration
16
+ - Updated all README examples to use `insert_before` instead of `use` for proper middleware placement
17
+
18
+ ### Fixed
19
+ - Fixed LoggerReporter to clone the logger parameter to prevent shared state issues (#77)
20
+ - Fixed view time precision issue by rounding to 2 decimal places
21
+ - Fixed invalid byte sequence handling for parameter keys by properly managing string encodings (#54)
22
+ - Fixed various typos in code comments and spec descriptions (#87)
23
+ - Fixed specs to work with Ruby 3.4's hash inspect format changes
24
+
25
+ ### Documentation
26
+ - Clarified middleware placement requirements in README - must be inserted before Grape::Middleware::Error (#74)
27
+ - Added gem version badge to README
28
+
29
+ [2.0.0]: https://github.com/aserafin/grape_logging/compare/v1.8.4...v2.0.0
30
+
31
+ ## [1.8.4] - 2021-10-29
32
+
33
+ ### Fixed
34
+ - Rails 6 compatibility improvements
35
+ - Various bug fixes and dependency updates
36
+
37
+ [1.8.4]: https://github.com/aserafin/grape_logging/compare/v1.8.3...v1.8.4
38
+
39
+ ## [1.8.3] - 2020-02-27
40
+
41
+ ### Fixed
42
+ - Performance improvements
43
+ - Bug fixes for edge cases
44
+
45
+ [1.8.3]: https://github.com/aserafin/grape_logging/compare/v1.8.2...v1.8.3
46
+
47
+ ## [1.8.2] - 2019-10-08
48
+
49
+ ### Fixed
50
+ - Thread safety improvements
51
+ - Minor bug fixes
52
+
53
+ Note: This version was tagged as "v.1.8.2" (with extra dot)
54
+
55
+ [1.8.2]: https://github.com/aserafin/grape_logging/compare/v1.8.1...v.1.8.2
56
+
57
+ ## [1.8.1] - 2019-08-07
58
+
59
+ ### Fixed
60
+ - Bug fixes for parameter filtering
61
+ - Improved error handling
62
+
63
+ [1.8.1]: https://github.com/aserafin/grape_logging/compare/v1.8.0...v1.8.1
64
+
65
+ ## [1.8.0] - 2019-05-30
66
+
67
+ ### Added
68
+ - Rails formatter for better Rails integration
69
+ - Improved Rails instrumentation support
70
+
71
+ [1.8.0]: https://github.com/aserafin/grape_logging/compare/v1.7.0...v1.8.0
72
+
73
+ ## [1.7.0] - 2017-11-09
74
+
75
+ ### Added
76
+ - Logstash formatter for ELK stack integration
77
+ - Enhanced JSON formatting options
78
+
79
+ [1.7.0]: https://github.com/aserafin/grape_logging/compare/v1.6.0...v1.7.0
80
+
81
+ ## [1.6.0] - 2017-07-20
82
+
83
+ ### Added
84
+ - MultiIO support for logging to multiple destinations simultaneously
85
+ - Can now log to both file and STDOUT
86
+
87
+ [1.6.0]: https://github.com/aserafin/grape_logging/compare/v1.5.0...v1.6.0
88
+
89
+ ## [1.5.0] - 2017-06-15
90
+
91
+ ### Added
92
+ - Configurable log levels
93
+ - Better control over logging verbosity
94
+
95
+ [1.5.0]: https://github.com/aserafin/grape_logging/compare/v1.4.0...v1.5.0
96
+
97
+ ## [1.4.0] - 2017-01-12
98
+
99
+ ### Added
100
+ - FilterParameters logger for sensitive parameter filtering
101
+ - Automatic Rails filter_parameters integration when available
102
+
103
+ [1.4.0]: https://github.com/aserafin/grape_logging/compare/v1.3.0...v1.4.0
104
+
105
+ ## [1.3.0] - 2016-12-08
106
+
107
+ ### Added
108
+ - RequestHeaders logger for logging HTTP request headers
109
+ - ClientEnv logger for logging client IP and user agent
110
+
111
+ [1.3.0]: https://github.com/aserafin/grape_logging/compare/v1.2.1...v1.3.0
112
+
113
+ ## [1.2.1] - 2016-04-14
114
+
115
+ ### Added
116
+ - JSON formatter for structured logging
117
+ - Rails instrumentation support via ActiveSupport::Notifications
118
+
119
+ ### Fixed
120
+ - Parameter handling improvements
121
+
122
+ [1.2.1]: https://github.com/aserafin/grape_logging/compare/v1.2.0...v1.2.1
123
+
124
+ ## [1.2.0] - 2016-01-21
125
+
126
+ ### Added
127
+ - Response logger for logging response details
128
+ - Improved parameter logging
129
+
130
+ ### Changed
131
+ - Better integration with Grape middleware stack
132
+
133
+ [1.2.0]: https://github.com/aserafin/grape_logging/compare/v1.1.3...v1.2.0
134
+
135
+ ## [1.1.3] - 2015-12-03
136
+
137
+ ### Fixed
138
+ - Bug fixes for Grape 0.14 compatibility
139
+ - Improved error handling
140
+
141
+ [1.1.3]: https://github.com/aserafin/grape_logging/compare/v1.1.2...v1.1.3
142
+
143
+ ## [1.1.2] - 2015-11-19
144
+
145
+ ### Fixed
146
+ - Performance optimizations
147
+ - Minor bug fixes
148
+
149
+ [1.1.2]: https://github.com/aserafin/grape_logging/compare/v1.1.1...v1.1.2
150
+
151
+ ## [1.1.1] - 2015-11-12
152
+
153
+ ### Fixed
154
+ - Critical bug fix for middleware initialization
155
+
156
+ Note: This version was tagged as "v.1.1.1" (with extra dot)
157
+
158
+ [1.1.1]: https://github.com/aserafin/grape_logging/compare/v1.1.0...v.1.1.1
159
+
160
+ ## [1.1.0] - 2015-11-09
161
+
162
+ ### Added
163
+ - Pluggable logger architecture
164
+ - Support for custom loggers via include option
165
+ - Base logger class for extending functionality
166
+
167
+ ### Changed
168
+ - Refactored middleware for better extensibility
169
+
170
+ [1.1.0]: https://github.com/aserafin/grape_logging/compare/v1.0.3...v1.1.0
171
+
172
+ ## [1.0.3] - 2015-11-05
173
+
174
+ ### Fixed
175
+ - Compatibility fixes for different Grape versions
176
+ - Bug fixes
177
+
178
+ [1.0.3]: https://github.com/aserafin/grape_logging/compare/v1.0.2...v1.0.3
179
+
180
+ ## [1.0.2] - 2015-10-29
181
+
182
+ ### Fixed
183
+ - Minor bug fixes and improvements
184
+
185
+ [1.0.2]: https://github.com/aserafin/grape_logging/compare/v1.0.1...v1.0.2
186
+
187
+ ## [1.0.1] - 2015-10-22
188
+
189
+ ### Fixed
190
+ - Initial bug fixes after 1.0 release
191
+
192
+ [1.0.1]: https://github.com/aserafin/grape_logging/compare/v1.0...v1.0.1
193
+
194
+ ## [1.0] - 2015-10-15
195
+
196
+ ### Added
197
+ - Initial release
198
+ - Request logging middleware for Grape APIs
199
+ - Basic request/response logging
200
+ - Configurable formatters
201
+ - Time tracking (total, db, view)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,110 @@
1
+ # Contributing to grape_logging
2
+
3
+ This project is work of many contributors. You're encouraged to submit pull requests, propose features and discuss issues.
4
+
5
+ ## Fork the Project
6
+
7
+ Fork the project on Github and check out your copy.
8
+
9
+ ```
10
+ git clone https://github.com/contributor/grape_logging.git
11
+ cd grape_logging
12
+ git remote add upstream https://github.com/aserafin/grape_logging.git
13
+ ```
14
+
15
+ ## Create a Topic Branch
16
+
17
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
18
+
19
+ ```
20
+ git checkout master
21
+ git pull upstream master
22
+ git checkout -b my-feature-branch
23
+ ```
24
+
25
+ ## Bundle Install and Test
26
+
27
+ Ensure that you can build the project and run tests.
28
+
29
+ ```
30
+ bundle install
31
+ bundle exec rake
32
+ ```
33
+
34
+ ## Write Tests
35
+
36
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to the spec directory.
37
+
38
+ ## Write Code
39
+
40
+ Implement your feature or bug fix.
41
+
42
+ Ruby style is enforced with RuboCop. Run `bundle exec rubocop` and fix any style issues highlighted.
43
+
44
+ Make sure that `bundle exec rake` completes without errors.
45
+
46
+ ## Write Documentation
47
+
48
+ Document any external behavior in the README.md.
49
+
50
+ ## Update Changelog
51
+
52
+ Add a line to Changelog.md under *Next Release*. Make it look like every other line, including your name and link to your Github account.
53
+
54
+ ## Commit Changes
55
+
56
+ Make sure git knows your name and email address:
57
+
58
+ ```
59
+ git config --global user.name "Your Name"
60
+ git config --global user.email "contributor@example.com"
61
+ ```
62
+
63
+ Writing good commit logs is important. A commit log should describe what changed and why.
64
+
65
+ ```
66
+ git add ...
67
+ git commit
68
+ ```
69
+
70
+ ## Push
71
+
72
+ ```
73
+ git push origin my-feature-branch
74
+ ```
75
+
76
+ ## Make a Pull Request
77
+
78
+ Go to https://github.com/contributor/grape_logging and select your feature branch. Click the 'Pull Request' button and fill out the form.
79
+
80
+ We'll try to review pull requests within a few days but as this is maintained by a small group of volunteers there is no guarantee that we'll look at it within any time frame, or at all. There's no maintenance guarantee.
81
+
82
+ ## Discuss and Update
83
+
84
+ You may get feedback or requests for changes to your pull request. This is a big part of the submission process so don't be discouraged!
85
+
86
+ Some things that will increase the chance that your pull request is accepted:
87
+
88
+ - Write tests.
89
+ - Follow the Ruby style guide.
90
+ - Write a good commit message.
91
+
92
+ If you'd like to discuss a feature or bug fix before starting work, please [create an issue](https://github.com/aserafin/grape_logging/issues) first. This helps ensure your contribution aligns with the project's direction and avoids duplicate efforts.
93
+
94
+ ## Rebase
95
+
96
+ If you've been working on a change for a while, rebase with upstream/master.
97
+
98
+ ```
99
+ git fetch upstream
100
+ git rebase upstream/master
101
+ git push origin my-feature-branch -f
102
+ ```
103
+
104
+ ## Be Patient
105
+
106
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang in there!
107
+
108
+ ## Thank You
109
+
110
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # grape_logging
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/aserafin/grape_logging/badges/gpa.svg)](https://codeclimate.com/github/aserafin/grape_logging)
4
- [![Build Status](https://travis-ci.org/aserafin/grape_logging.svg?branch=master)](https://travis-ci.org/aserafin/grape_logging)
3
+ [![Gem Version](https://badge.fury.io/rb/grape_logging.svg)](https://badge.fury.io/rb/grape_logging)
4
+ [![CI](https://github.com/aserafin/grape_logging/actions/workflows/ci.yml/badge.svg)](https://github.com/aserafin/grape_logging/actions/workflows/ci.yml)
5
5
 
6
6
  ## Installation
7
7
 
@@ -19,12 +19,12 @@ Or install it yourself as:
19
19
 
20
20
  ## Basic Usage
21
21
 
22
- In your api file (somewhere on the top)
22
+ In your API file (somewhere on the top), insert grape logging middleware before grape error middleware. This is important due to the behaviour of `lib/grape/middleware/error.rb`, which manipulates the status of the response when there is an error.
23
23
 
24
24
  ```ruby
25
25
  require 'grape_logging'
26
26
  logger.formatter = GrapeLogging::Formatters::Default.new
27
- use GrapeLogging::Middleware::RequestLogger, { logger: logger }
27
+ insert_before Grape::Middleware::Error, GrapeLogging::Middleware::RequestLogger, { logger: logger }
28
28
  ```
29
29
 
30
30
  **ProTip:** If your logger doesn't support setting formatter you can remove this line - it's optional
@@ -114,7 +114,7 @@ end
114
114
  You can change the formatter like so
115
115
  ```ruby
116
116
  class MyAPI < Grape::API
117
- use GrapeLogging::Middleware::RequestLogger, logger: logger, formatter: MyFormatter.new
117
+ insert_before Grape::Middleware::Error, GrapeLogging::Middleware::RequestLogger, logger: logger, formatter: MyFormatter.new
118
118
  end
119
119
  ```
120
120
 
@@ -125,7 +125,8 @@ If you prefer some other format I strongly encourage you to do pull request with
125
125
  You can include logging of other parts of the request / response cycle by including subclasses of `GrapeLogging::Loggers::Base`
126
126
  ```ruby
127
127
  class MyAPI < Grape::API
128
- use GrapeLogging::Middleware::RequestLogger,
128
+ insert_before Grape::Middleware::Error,
129
+ GrapeLogging::Middleware::RequestLogger,
129
130
  logger: logger,
130
131
  include: [ GrapeLogging::Loggers::Response.new,
131
132
  GrapeLogging::Loggers::FilterParameters.new,
@@ -158,7 +159,8 @@ You can control the level used to log. The default is `info`.
158
159
 
159
160
  ```ruby
160
161
  class MyAPI < Grape::API
161
- use GrapeLogging::Middleware::RequestLogger,
162
+ insert_before Grape::Middleware::Error,
163
+ GrapeLogging::Middleware::RequestLogger,
162
164
  logger: logger,
163
165
  log_level: 'debug'
164
166
  end
@@ -170,7 +172,8 @@ You can choose to not pass the logger to ```grape_logging``` but instead send lo
170
172
  First, config ```grape_logging```, like that:
171
173
  ```ruby
172
174
  class MyAPI < Grape::API
173
- use GrapeLogging::Middleware::RequestLogger,
175
+ insert_before Grape::Middleware::Error,
176
+ GrapeLogging::Middleware::RequestLogger,
174
177
  instrumentation_key: 'grape_key',
175
178
  include: [ GrapeLogging::Loggers::Response.new,
176
179
  GrapeLogging::Loggers::FilterParameters.new ]
@@ -206,10 +209,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
206
209
 
207
210
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
208
211
 
212
+ For maintainers releasing a new version, please see [Releasing.md](Releasing.md).
213
+
209
214
  ## Contributing
210
215
 
211
- 1. Fork it ( https://github.com/aserafin/grape_logging/fork )
212
- 2. Create your feature branch (`git checkout -b my-new-feature`)
213
- 3. Commit your changes (`git commit -am 'Add some feature'`)
214
- 4. Push to the branch (`git push origin my-new-feature`)
215
- 5. Create a new Pull Request
216
+ See [Contributing.md](Contributing.md).
data/RELEASING.md ADDED
@@ -0,0 +1,111 @@
1
+ # Releasing grape_logging
2
+
3
+ There're no particular rules about when to release grape_logging. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Pre-flight Checks
6
+
7
+ Run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded in [GitHub Actions](https://github.com/aserafin/grape_logging/actions) for all supported platforms.
15
+
16
+ ### Update Changelog
17
+
18
+ Change "Next Release" in [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md) to the new version and date:
19
+
20
+ ```
21
+ ## [1.8.5] - 2024-06-28
22
+
23
+ ### Changed
24
+ - Description of changes
25
+
26
+ ### Fixed
27
+ - Description of fixes
28
+
29
+ ### Added
30
+ - Description of additions
31
+
32
+ [1.8.5]: https://github.com/aserafin/grape_logging/compare/v1.8.4...v1.8.5
33
+ ```
34
+
35
+ Remove the line with "Your contribution here.", since there will be no more contributions to this release.
36
+
37
+ Only include the sections (Changed, Fixed, Added, etc.) that have actual changes.
38
+
39
+ Commit your changes.
40
+
41
+ ```shell
42
+ git add CHANGELOG.md lib/grape_logging/version.rb
43
+ git commit -m "Preparing for release, 1.8.5."
44
+ git push
45
+ ```
46
+
47
+ ### Release on RubyGems and GitHub
48
+
49
+ #### Option 1: Automated (Recommended)
50
+
51
+ Use the combined task that releases the gem and creates a GitHub release:
52
+
53
+ ```shell
54
+ rake github_release
55
+ ```
56
+
57
+ This will:
58
+ 1. Build and push the gem to RubyGems
59
+ 2. Create and push the git tag
60
+ 3. Create a GitHub release with auto-generated changelog
61
+
62
+ #### Option 2: Manual
63
+
64
+ First, release the gem:
65
+
66
+ ```shell
67
+ rake release
68
+ ```
69
+
70
+ Output will look something like:
71
+ ```
72
+ grape_logging 1.8.5 built to pkg/grape_logging-1.8.5.gem.
73
+ Tagged v1.8.5.
74
+ Pushed git commits and tags.
75
+ Pushed grape_logging 1.8.5 to rubygems.org.
76
+ ```
77
+
78
+ Then create the GitHub release on the web or using `gh`:
79
+
80
+ ```
81
+ gh release create v1.8.5 --generate-notes --verify-tag
82
+ ```
83
+
84
+ This uses GitHub's automatic changelog generation feature to create release notes from merged pull requests and commits since the last release.
85
+
86
+ ### Prepare for the Next Version
87
+
88
+ Modify `lib/grape_logging/version.rb`, increment the version number (eg. change `1.8.5` to `1.8.6`).
89
+
90
+ ```ruby
91
+ module GrapeLogging
92
+ VERSION = '1.8.6'.freeze
93
+ end
94
+ ```
95
+
96
+ Add the next release to [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md).
97
+
98
+ ```
99
+ ## [Next Release]
100
+
101
+ ### Changed or Fixed or Added
102
+ - Your contribution here.
103
+ ```
104
+
105
+ Commit your changes.
106
+
107
+ ```
108
+ git add CHANGELOG.md lib/grape_logging/version.rb
109
+ git commit -m "Bump version to 1.8.6."
110
+ git push
111
+ ```
data/Rakefile CHANGED
@@ -1,2 +1,35 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ desc 'Release gem and create GitHub release'
9
+ task github_release: :release do
10
+ require 'grape_logging/version'
11
+
12
+ version = "v#{GrapeLogging::VERSION}"
13
+
14
+ # Check if gh CLI is available
15
+ unless system('which gh > /dev/null 2>&1')
16
+ puts "\n⚠️ GitHub CLI (gh) not found"
17
+ puts "To create a GitHub release with auto-generated changelog, install gh:"
18
+ puts " brew install gh # macOS with Homebrew"
19
+ puts " # or visit: https://github.com/cli/cli#installation"
20
+ puts "\nYou can manually create the release with:"
21
+ puts " gh release create v#{GrapeLogging::VERSION} --generate-notes"
22
+ next
23
+ end
24
+
25
+ # Create GitHub release
26
+ puts "\nCreating GitHub release #{version}..."
27
+
28
+ if system('gh', 'release', 'create', version, '--generate-notes', '--verify-tag')
29
+ puts "✅ GitHub release #{version} created successfully"
30
+ else
31
+ puts "❌ Failed to create GitHub release"
32
+ puts "You can manually create it with:"
33
+ puts " gh release create '#{version}' --generate-notes --verify-tag"
34
+ end
35
+ end
data/bin/console CHANGED
File without changes
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'grape_logging/version'
@@ -19,11 +18,9 @@ Gem::Specification.new do |spec|
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
19
  spec.require_paths = ['lib']
21
20
 
22
- spec.add_dependency 'grape'
21
+ spec.add_dependency 'grape', '< 2.4.0'
23
22
  spec.add_dependency 'rack'
24
23
 
25
- spec.add_development_dependency 'bundler', '~> 1.8'
26
- spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rake', '~> 13.3'
27
25
  spec.add_development_dependency 'rspec', '~> 3.5'
28
- spec.add_development_dependency 'pry-byebug', '~> 3.4.2'
29
26
  end
@@ -29,7 +29,23 @@ module GrapeLogging
29
29
  end
30
30
 
31
31
  def clean_parameters(parameters)
32
- parameter_filter.filter(parameters).reject{ |key, _value| @exceptions.include?(key) }
32
+ original_encoding_map = build_encoding_map(parameters)
33
+ params = transform_key_encoding(parameters, Hash.new{ |h, _| [Encoding::ASCII_8BIT, h] })
34
+ cleaned_params = parameter_filter.filter(params).reject{ |key, _value| @exceptions.include?(key) }
35
+ transform_key_encoding(cleaned_params, original_encoding_map)
36
+ end
37
+
38
+ def build_encoding_map(parameters)
39
+ parameters.each_with_object({}) do |(k, v), h|
40
+ h[k.dup.force_encoding(Encoding::ASCII_8BIT)] = [k.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
41
+ end
42
+ end
43
+
44
+ def transform_key_encoding(parameters, encoding_map)
45
+ parameters.each_with_object({}) do |(k, v), h|
46
+ encoding, children_encoding_map = encoding_map[k]
47
+ h[k.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
48
+ end
33
49
  end
34
50
  end
35
51
  end
@@ -9,7 +9,7 @@ module GrapeLogging
9
9
 
10
10
  # In some cases, response.body is not parseable by JSON.
11
11
  # For example, if you POST on a PUT endpoint, response.body is egal to """".
12
- # It's strange but it's the Grape behavior...
12
+ # It's strange, but it's the Grape behavior...
13
13
  def serialized_response_body(response)
14
14
 
15
15
  if response.respond_to?(:body)
@@ -1,4 +1,4 @@
1
- require 'grape/middleware/base'
1
+ require 'grape'
2
2
 
3
3
  module GrapeLogging
4
4
  module Middleware
@@ -37,7 +37,7 @@ module GrapeLogging
37
37
  @response_status = status
38
38
  @response_body = response
39
39
 
40
- # Perform repotters
40
+ # Perform reporters
41
41
  @reporter.perform(collect_parameters)
42
42
 
43
43
  # Invoke loggers
@@ -56,20 +56,18 @@ module GrapeLogging
56
56
 
57
57
  # Catch error
58
58
  error = catch(:error) do
59
- begin
60
- @app_response = @app.call(@env)
61
- rescue => e
62
- # Log as 500 + message
63
- after(e.respond_to?(:status) ? e.status : 500, e.message)
64
-
65
- # Re-raise exception
66
- raise e
67
- end
59
+ @app_response = @app.call(@env)
68
60
  nil
61
+ rescue StandardError => e
62
+ # Log as 500 + message
63
+ after(e.respond_to?(:status) ? e.status : 500, e.message)
64
+
65
+ # Re-raise exception
66
+ raise e
69
67
  end
70
68
 
71
69
  # Get status & response from app_response
72
- # when no error occures.
70
+ # when no error occurs.
73
71
  if error
74
72
  # Call with error & response
75
73
  after(error[:status], error[:message])
@@ -100,7 +98,8 @@ module GrapeLogging
100
98
  method: request.request_method,
101
99
  path: request.path,
102
100
  params: request.params,
103
- host: request.host
101
+ host: request.host,
102
+ request_id: env['action_dispatch.request_id'],
104
103
  }
105
104
  end
106
105
 
@@ -115,7 +114,7 @@ module GrapeLogging
115
114
  end
116
115
 
117
116
  def view_runtime
118
- total_runtime - db_runtime
117
+ (total_runtime - db_runtime).round(2)
119
118
  end
120
119
 
121
120
  def db_runtime
@@ -1,7 +1,7 @@
1
1
  module Reporters
2
2
  class LoggerReporter
3
3
  def initialize(logger, formatter, log_level)
4
- @logger = logger || Logger.new(STDOUT)
4
+ @logger = logger.clone || Logger.new(STDOUT)
5
5
  @log_level = log_level || :info
6
6
  if @logger.respond_to?(:formatter=)
7
7
  @logger.formatter = formatter || @logger.formatter || GrapeLogging::Formatters::Default.new
@@ -1,3 +1,3 @@
1
1
  module GrapeLogging
2
- VERSION = '1.8.4'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,29 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aserafin
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: grape
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "<"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 2.4.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "<"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: 2.4.0
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rack
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +37,20 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.8'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.8'
55
40
  - !ruby/object:Gem::Dependency
56
41
  name: rake
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - "~>"
60
45
  - !ruby/object:Gem::Version
61
- version: '10.0'
46
+ version: '13.3'
62
47
  type: :development
63
48
  prerelease: false
64
49
  version_requirements: !ruby/object:Gem::Requirement
65
50
  requirements:
66
51
  - - "~>"
67
52
  - !ruby/object:Gem::Version
68
- version: '10.0'
53
+ version: '13.3'
69
54
  - !ruby/object:Gem::Dependency
70
55
  name: rspec
71
56
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +65,6 @@ dependencies:
80
65
  - - "~>"
81
66
  - !ruby/object:Gem::Version
82
67
  version: '3.5'
83
- - !ruby/object:Gem::Dependency
84
- name: pry-byebug
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 3.4.2
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 3.4.2
97
68
  description: This gem provides simple request logging for Grape with just few lines
98
69
  of code you have to put in your project! In return you will get response codes,
99
70
  paths, parameters and more!
@@ -103,11 +74,14 @@ executables: []
103
74
  extensions: []
104
75
  extra_rdoc_files: []
105
76
  files:
77
+ - ".github/workflows/ci.yml"
106
78
  - ".gitignore"
107
- - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - CONTRIBUTING.md
108
81
  - Gemfile
109
82
  - LICENSE.txt
110
83
  - README.md
84
+ - RELEASING.md
111
85
  - Rakefile
112
86
  - bin/console
113
87
  - bin/setup
@@ -134,7 +108,6 @@ homepage: http://github.com/aserafin/grape_logging
134
108
  licenses:
135
109
  - MIT
136
110
  metadata: {}
137
- post_install_message:
138
111
  rdoc_options: []
139
112
  require_paths:
140
113
  - lib
@@ -149,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
122
  - !ruby/object:Gem::Version
150
123
  version: '0'
151
124
  requirements: []
152
- rubygems_version: 3.1.2
153
- signing_key:
125
+ rubygems_version: 3.6.7
154
126
  specification_version: 4
155
127
  summary: Out of the box request logging for Grape!
156
128
  test_files: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.1
4
- cache: bundler
5
- script:
6
- - bundle exec rspec