Merge branch 'add-rubocop' into add-all-todos

This commit is contained in:
Pieter Oliver 2025-07-10 10:22:09 +01:00 committed by GitHub
commit ba45a7dbf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 492 additions and 38 deletions

View file

@ -32,5 +32,5 @@ jobs:
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run tests
- name: Run RuboCop
run: bundle exec rake rubocop

View file

@ -12,7 +12,7 @@
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'grape_logging.gemspec'
- "grape_logging.gemspec"
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
@ -20,7 +20,7 @@ Gemspec/DevelopmentDependencies:
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'grape_logging.gemspec'
- "grape_logging.gemspec"
# Offense count: 1
# Configuration parameters: Severity, Include.
@ -28,7 +28,6 @@ Gemspec/RequireMFA:
Gemspec/RequiredRubyVersion:
Exclude:
- 'grape_logging.gemspec'
# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
Lint/DuplicateBranch:
@ -39,7 +38,7 @@ Lint/DuplicateBranch:
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'lib/grape_logging/loggers/filter_parameters.rb'
- "lib/grape_logging/loggers/filter_parameters.rb"
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
@ -73,16 +72,16 @@ Metrics/PerceivedComplexity:
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'spec/lib/grape_logging/formatters/rails_spec.rb'
- "spec/lib/grape_logging/formatters/rails_spec.rb"
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: MinBranchesCount.
Style/CaseLikeIf:
Exclude:
- 'lib/grape_logging/formatters/default.rb'
- 'lib/grape_logging/formatters/logstash.rb'
- 'lib/grape_logging/formatters/rails.rb'
- "lib/grape_logging/formatters/default.rb"
- "lib/grape_logging/formatters/logstash.rb"
- "lib/grape_logging/formatters/rails.rb"
# Offense count: 17
# Configuration parameters: AllowedConstants.
@ -100,15 +99,7 @@ Style/FrozenStringLiteralComment:
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'lib/grape_logging/reporters/logger_reporter.rb'
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, Autocorrect.
# SupportedStyles: module_function, extend_self, forbidden
Style/ModuleFunction:
Exclude:
- 'lib/grape_logging/timings.rb'
- "lib/grape_logging/reporters/logger_reporter.rb"
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
@ -118,13 +109,22 @@ Style/MutableConstant:
Exclude:
- 'lib/grape_logging/version.rb'
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- "spec/**/*"
- "lib/grape_logging/formatters/rails.rb"
# Offense count: 10
Style/OpenStructUse:
Exclude:
- 'spec/lib/grape_logging/loggers/client_env_spec.rb'
- 'spec/lib/grape_logging/loggers/filter_parameters_spec.rb'
- 'spec/lib/grape_logging/loggers/request_headers_spec.rb'
- 'spec/lib/grape_logging/loggers/response_spec.rb'
- "spec/lib/grape_logging/loggers/client_env_spec.rb"
- "spec/lib/grape_logging/loggers/filter_parameters_spec.rb"
- "spec/lib/grape_logging/loggers/request_headers_spec.rb"
- "spec/lib/grape_logging/loggers/response_spec.rb"
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
@ -138,7 +138,7 @@ Style/SafeNavigation:
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'lib/grape_logging/loggers/request_headers.rb'
- "lib/grape_logging/loggers/request_headers.rb"
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
@ -146,16 +146,16 @@ Style/SlicingWithRange:
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
Exclude:
- 'spec/spec_helper.rb'
- "spec/spec_helper.rb"
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/grape_logging/formatters/json.rb'
- 'lib/grape_logging/formatters/lograge.rb'
- 'lib/grape_logging/formatters/logstash.rb'
- "lib/grape_logging/formatters/json.rb"
- "lib/grape_logging/formatters/lograge.rb"
- "lib/grape_logging/formatters/logstash.rb"
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
@ -163,11 +163,11 @@ Style/StringConcatenation:
# AllowedMethods: define_method
Style/SymbolProc:
Exclude:
- 'lib/grape_logging/util/parameter_filter.rb'
- "lib/grape_logging/util/parameter_filter.rb"
# Offense count: 10
# Offense count: 11
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 205
Max: 203

201
CHANGELOG.md Normal file
View file

@ -0,0 +1,201 @@
# Changelog
## [2.0.1] - Unreleased
### Changed or Fixed or Added
* Your contribution here.
[2.0.1]: https://github.com/aserafin/grape_logging/compare/v2.0.0...master
## [2.0.0] - 2025-07-09
### Changed
- **BREAKING**: Updated to support Grape 2.1 and Rack 3.1
- Minimum supported Ruby version is now 3.0
- Replaced Travis CI with GitHub Actions for continuous integration
- Updated all README examples to use `insert_before` instead of `use` for proper middleware placement
### Fixed
- Fixed LoggerReporter to clone the logger parameter to prevent shared state issues (#77)
- Fixed view time precision issue by rounding to 2 decimal places
- Fixed invalid byte sequence handling for parameter keys by properly managing string encodings (#54)
- Fixed various typos in code comments and spec descriptions (#87)
- Fixed specs to work with Ruby 3.4's hash inspect format changes
### Documentation
- Clarified middleware placement requirements in README - must be inserted before Grape::Middleware::Error (#74)
- Added gem version badge to README
[2.0.0]: https://github.com/aserafin/grape_logging/compare/v1.8.4...v2.0.0
## [1.8.4] - 2021-10-29
### Fixed
- Rails 6 compatibility improvements
- Various bug fixes and dependency updates
[1.8.4]: https://github.com/aserafin/grape_logging/compare/v1.8.3...v1.8.4
## [1.8.3] - 2020-02-27
### Fixed
- Performance improvements
- Bug fixes for edge cases
[1.8.3]: https://github.com/aserafin/grape_logging/compare/v1.8.2...v1.8.3
## [1.8.2] - 2019-10-08
### Fixed
- Thread safety improvements
- Minor bug fixes
Note: This version was tagged as "v.1.8.2" (with extra dot)
[1.8.2]: https://github.com/aserafin/grape_logging/compare/v1.8.1...v.1.8.2
## [1.8.1] - 2019-08-07
### Fixed
- Bug fixes for parameter filtering
- Improved error handling
[1.8.1]: https://github.com/aserafin/grape_logging/compare/v1.8.0...v1.8.1
## [1.8.0] - 2019-05-30
### Added
- Rails formatter for better Rails integration
- Improved Rails instrumentation support
[1.8.0]: https://github.com/aserafin/grape_logging/compare/v1.7.0...v1.8.0
## [1.7.0] - 2017-11-09
### Added
- Logstash formatter for ELK stack integration
- Enhanced JSON formatting options
[1.7.0]: https://github.com/aserafin/grape_logging/compare/v1.6.0...v1.7.0
## [1.6.0] - 2017-07-20
### Added
- MultiIO support for logging to multiple destinations simultaneously
- Can now log to both file and STDOUT
[1.6.0]: https://github.com/aserafin/grape_logging/compare/v1.5.0...v1.6.0
## [1.5.0] - 2017-06-15
### Added
- Configurable log levels
- Better control over logging verbosity
[1.5.0]: https://github.com/aserafin/grape_logging/compare/v1.4.0...v1.5.0
## [1.4.0] - 2017-01-12
### Added
- FilterParameters logger for sensitive parameter filtering
- Automatic Rails filter_parameters integration when available
[1.4.0]: https://github.com/aserafin/grape_logging/compare/v1.3.0...v1.4.0
## [1.3.0] - 2016-12-08
### Added
- RequestHeaders logger for logging HTTP request headers
- ClientEnv logger for logging client IP and user agent
[1.3.0]: https://github.com/aserafin/grape_logging/compare/v1.2.1...v1.3.0
## [1.2.1] - 2016-04-14
### Added
- JSON formatter for structured logging
- Rails instrumentation support via ActiveSupport::Notifications
### Fixed
- Parameter handling improvements
[1.2.1]: https://github.com/aserafin/grape_logging/compare/v1.2.0...v1.2.1
## [1.2.0] - 2016-01-21
### Added
- Response logger for logging response details
- Improved parameter logging
### Changed
- Better integration with Grape middleware stack
[1.2.0]: https://github.com/aserafin/grape_logging/compare/v1.1.3...v1.2.0
## [1.1.3] - 2015-12-03
### Fixed
- Bug fixes for Grape 0.14 compatibility
- Improved error handling
[1.1.3]: https://github.com/aserafin/grape_logging/compare/v1.1.2...v1.1.3
## [1.1.2] - 2015-11-19
### Fixed
- Performance optimizations
- Minor bug fixes
[1.1.2]: https://github.com/aserafin/grape_logging/compare/v1.1.1...v1.1.2
## [1.1.1] - 2015-11-12
### Fixed
- Critical bug fix for middleware initialization
Note: This version was tagged as "v.1.1.1" (with extra dot)
[1.1.1]: https://github.com/aserafin/grape_logging/compare/v1.1.0...v.1.1.1
## [1.1.0] - 2015-11-09
### Added
- Pluggable logger architecture
- Support for custom loggers via include option
- Base logger class for extending functionality
### Changed
- Refactored middleware for better extensibility
[1.1.0]: https://github.com/aserafin/grape_logging/compare/v1.0.3...v1.1.0
## [1.0.3] - 2015-11-05
### Fixed
- Compatibility fixes for different Grape versions
- Bug fixes
[1.0.3]: https://github.com/aserafin/grape_logging/compare/v1.0.2...v1.0.3
## [1.0.2] - 2015-10-29
### Fixed
- Minor bug fixes and improvements
[1.0.2]: https://github.com/aserafin/grape_logging/compare/v1.0.1...v1.0.2
## [1.0.1] - 2015-10-22
### Fixed
- Initial bug fixes after 1.0 release
[1.0.1]: https://github.com/aserafin/grape_logging/compare/v1.0...v1.0.1
## [1.0] - 2015-10-15
### Added
- Initial release
- Request logging middleware for Grape APIs
- Basic request/response logging
- Configurable formatters
- Time tracking (total, db, view)

110
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,110 @@
# Contributing to grape_logging
This project is work of many contributors. You're encouraged to submit pull requests, propose features and discuss issues.
## Fork the Project
Fork the project on Github and check out your copy.
```
git clone https://github.com/contributor/grape_logging.git
cd grape_logging
git remote add upstream https://github.com/aserafin/grape_logging.git
```
## Create a Topic Branch
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
```
git checkout master
git pull upstream master
git checkout -b my-feature-branch
```
## Bundle Install and Test
Ensure that you can build the project and run tests.
```
bundle install
bundle exec rake
```
## Write Tests
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.
## Write Code
Implement your feature or bug fix.
Ruby style is enforced with RuboCop. Run `bundle exec rubocop` and fix any style issues highlighted.
Make sure that `bundle exec rake` completes without errors.
## Write Documentation
Document any external behavior in the README.md.
## Update Changelog
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.
## Commit Changes
Make sure git knows your name and email address:
```
git config --global user.name "Your Name"
git config --global user.email "contributor@example.com"
```
Writing good commit logs is important. A commit log should describe what changed and why.
```
git add ...
git commit
```
## Push
```
git push origin my-feature-branch
```
## Make a Pull Request
Go to https://github.com/contributor/grape_logging and select your feature branch. Click the 'Pull Request' button and fill out the form.
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.
## Discuss and Update
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!
Some things that will increase the chance that your pull request is accepted:
- Write tests.
- Follow the Ruby style guide.
- Write a good commit message.
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.
## Rebase
If you've been working on a change for a while, rebase with upstream/master.
```
git fetch upstream
git rebase upstream/master
git push origin my-feature-branch -f
```
## Be Patient
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!
## Thank You
Please do know that we really appreciate and value your time and work. We love you, really.

View file

@ -209,10 +209,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
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).
For maintainers releasing a new version, please see [Releasing.md](Releasing.md).
## Contributing
1. Fork it ( https://github.com/aserafin/grape_logging/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
See [Contributing.md](Contributing.md).

111
RELEASING.md Normal file
View file

@ -0,0 +1,111 @@
# Releasing grape_logging
There're no particular rules about when to release grape_logging. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
### Pre-flight Checks
Run tests, check that all tests succeed locally.
```
bundle install
rake
```
Check that the last build succeeded in [GitHub Actions](https://github.com/aserafin/grape_logging/actions) for all supported platforms.
### Update Changelog
Change "Next Release" in [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md) to the new version and date:
```
## [1.8.5] - 2024-06-28
### Changed
- Description of changes
### Fixed
- Description of fixes
### Added
- Description of additions
[1.8.5]: https://github.com/aserafin/grape_logging/compare/v1.8.4...v1.8.5
```
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
Only include the sections (Changed, Fixed, Added, etc.) that have actual changes.
Commit your changes.
```shell
git add CHANGELOG.md lib/grape_logging/version.rb
git commit -m "Preparing for release, 1.8.5."
git push
```
### Release on RubyGems and GitHub
#### Option 1: Automated (Recommended)
Use the combined task that releases the gem and creates a GitHub release:
```shell
rake github_release
```
This will:
1. Build and push the gem to RubyGems
2. Create and push the git tag
3. Create a GitHub release with auto-generated changelog
#### Option 2: Manual
First, release the gem:
```shell
rake release
```
Output will look something like:
```
grape_logging 1.8.5 built to pkg/grape_logging-1.8.5.gem.
Tagged v1.8.5.
Pushed git commits and tags.
Pushed grape_logging 1.8.5 to rubygems.org.
```
Then create the GitHub release on the web or using `gh`:
```
gh release create v1.8.5 --generate-notes --verify-tag
```
This uses GitHub's automatic changelog generation feature to create release notes from merged pull requests and commits since the last release.
### Prepare for the Next Version
Modify `lib/grape_logging/version.rb`, increment the version number (eg. change `1.8.5` to `1.8.6`).
```ruby
module GrapeLogging
VERSION = '1.8.6'.freeze
end
```
Add the next release to [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md).
```
## [Next Release]
### Changed or Fixed or Added
* Your contribution here.
```
Commit your changes.
```
git add CHANGELOG.md lib/grape_logging/version.rb
git commit -m "Bump version to 1.8.6."
git push
```

View file

@ -7,6 +7,37 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
RuboCop::RakeTask.new(:rubocop)
RuboCop::RakeTask.new(:rubocop) do |t|
t.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'Rakefile', 'Gemfile', 'grape_logging.gemspec']
end
task default: %i[spec rubocop]
desc 'Release gem and create GitHub release'
task github_release: :release do
require 'grape_logging/version'
version = "v#{GrapeLogging::VERSION}"
# Check if gh CLI is available
unless system('which gh > /dev/null 2>&1')
puts "\n⚠️ GitHub CLI (gh) not found"
puts 'To create a GitHub release with auto-generated changelog, install gh:'
puts ' brew install gh # macOS with Homebrew'
puts ' # or visit: https://github.com/cli/cli#installation'
puts "\nYou can manually create the release with:"
puts " gh release create v#{GrapeLogging::VERSION} --generate-notes"
next
end
# Create GitHub release
puts "\nCreating GitHub release #{version}..."
if system('gh', 'release', 'create', version, '--generate-notes', '--verify-tag')
puts "✅ GitHub release #{version} created successfully"
else
puts '❌ Failed to create GitHub release'
puts 'You can manually create it with:'
puts " gh release create '#{version}' --generate-notes --verify-tag"
end
end

View file

@ -23,5 +23,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.3'
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'rubocop'
# This is pinned to an exact version otherwise we can't know which rules
# are in play at any given time in different environments.
spec.add_development_dependency 'rubocop', '1.77.0'
end

View file

@ -1,3 +1,3 @@
module GrapeLogging
VERSION = '1.8.4'
VERSION = '2.0.1'
end