grape_logging 2.1.0 → 3.0.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 +4 -4
- data/.github/workflows/ci.yml +14 -1
- data/.rubocop.yml +14 -0
- data/.rubocop_todo.yml +160 -0
- data/CHANGELOG.md +15 -1
- data/RELEASING.md +4 -2
- data/Rakefile +15 -7
- data/grape_logging.gemspec +13 -7
- data/lib/grape_logging/formatters/default.rb +1 -0
- data/lib/grape_logging/formatters/logstash.rb +3 -3
- data/lib/grape_logging/formatters/rails.rb +3 -5
- data/lib/grape_logging/loggers/base.rb +1 -1
- data/lib/grape_logging/loggers/client_env.rb +1 -1
- data/lib/grape_logging/loggers/filter_parameters.rb +8 -6
- data/lib/grape_logging/loggers/request_headers.rb +0 -2
- data/lib/grape_logging/loggers/response.rb +2 -3
- data/lib/grape_logging/middleware/request_logger.rb +14 -12
- data/lib/grape_logging/multi_io.rb +2 -2
- data/lib/grape_logging/reporters/active_support_reporter.rb +1 -1
- data/lib/grape_logging/reporters/logger_reporter.rb +1 -3
- data/lib/grape_logging/timings.rb +5 -7
- data/lib/grape_logging/util/parameter_filter.rb +9 -7
- data/lib/grape_logging/version.rb +1 -1
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06aaf18280f4233ee64c9ec952860f1db9e6119ea832efc5a29d93601b73f0ce
|
4
|
+
data.tar.gz: bab90314228b6b136cb6b726328bcf06753ca808c6dd49d42b548356672f5e8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ad7895d92bfdbc1a581d2d618875419c5dc5eed78172d6b4785cf4ec62b466e634eab831a28f39b799c126d430643a5bf438d14ba31bba4e93bba368790e57
|
7
|
+
data.tar.gz: d917cfb3390d1b205133ee84d16b86b5b9904e3a8a16fdc05d987057a7fefb06df005a6e5b65b708c15546b973bfa8ebf64472ac9d471cc1c42b4f3dfea0d445
|
data/.github/workflows/ci.yml
CHANGED
@@ -20,4 +20,17 @@ jobs:
|
|
20
20
|
- name: Install dependencies
|
21
21
|
run: bundle install
|
22
22
|
- name: Run tests
|
23
|
-
run: bundle exec
|
23
|
+
run: bundle exec rake spec
|
24
|
+
lint:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- name: Checkout code
|
28
|
+
uses: actions/checkout@v4
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: "3.4"
|
32
|
+
bundler-cache: true
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run RuboCop
|
36
|
+
run: bundle exec rake rubocop
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
8
|
+
|
9
|
+
Metrics/ClassLength:
|
10
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
14
|
+
Max: 20
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2025-07-10 10:25:51 UTC using RuboCop version 1.77.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
|
11
|
+
# SupportedStyles: Gemfile, gems.rb, gemspec
|
12
|
+
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
|
13
|
+
Gemspec/DevelopmentDependencies:
|
14
|
+
Exclude:
|
15
|
+
- "grape_logging.gemspec"
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# This cop supports safe autocorrection (--autocorrect).
|
19
|
+
# Configuration parameters: Severity, Include.
|
20
|
+
# Include: **/*.gemspec
|
21
|
+
Gemspec/RequireMFA:
|
22
|
+
Exclude:
|
23
|
+
- "grape_logging.gemspec"
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Configuration parameters: Severity, Include.
|
27
|
+
# Include: **/*.gemspec
|
28
|
+
Gemspec/RequiredRubyVersion:
|
29
|
+
Exclude:
|
30
|
+
- "grape_logging.gemspec"
|
31
|
+
|
32
|
+
# Offense count: 1
|
33
|
+
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
|
34
|
+
Lint/DuplicateBranch:
|
35
|
+
Exclude:
|
36
|
+
- "lib/grape_logging/util/parameter_filter.rb"
|
37
|
+
|
38
|
+
# Offense count: 1
|
39
|
+
# Configuration parameters: AllowedParentClasses.
|
40
|
+
Lint/MissingSuper:
|
41
|
+
Exclude:
|
42
|
+
- "lib/grape_logging/loggers/filter_parameters.rb"
|
43
|
+
|
44
|
+
# Offense count: 3
|
45
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
46
|
+
Metrics/AbcSize:
|
47
|
+
Max: 38
|
48
|
+
|
49
|
+
# Offense count: 8
|
50
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
51
|
+
# AllowedMethods: refine
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Max: 90
|
54
|
+
|
55
|
+
# Offense count: 3
|
56
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
57
|
+
Metrics/CyclomaticComplexity:
|
58
|
+
Max: 18
|
59
|
+
|
60
|
+
# Offense count: 2
|
61
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
62
|
+
Metrics/PerceivedComplexity:
|
63
|
+
Max: 19
|
64
|
+
|
65
|
+
# Offense count: 2
|
66
|
+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
67
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
68
|
+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
69
|
+
Naming/VariableNumber:
|
70
|
+
Exclude:
|
71
|
+
- "spec/lib/grape_logging/formatters/rails_spec.rb"
|
72
|
+
|
73
|
+
# Offense count: 3
|
74
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
75
|
+
# Configuration parameters: MinBranchesCount.
|
76
|
+
Style/CaseLikeIf:
|
77
|
+
Exclude:
|
78
|
+
- "lib/grape_logging/formatters/default.rb"
|
79
|
+
- "lib/grape_logging/formatters/logstash.rb"
|
80
|
+
- "lib/grape_logging/formatters/rails.rb"
|
81
|
+
|
82
|
+
# Offense count: 17
|
83
|
+
# Configuration parameters: AllowedConstants.
|
84
|
+
Style/Documentation:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
# Offense count: 29
|
88
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
89
|
+
# Configuration parameters: EnforcedStyle.
|
90
|
+
# SupportedStyles: always, always_true, never
|
91
|
+
Style/FrozenStringLiteralComment:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
# Offense count: 1
|
95
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
96
|
+
Style/GlobalStdStream:
|
97
|
+
Exclude:
|
98
|
+
- "lib/grape_logging/reporters/logger_reporter.rb"
|
99
|
+
|
100
|
+
# Offense count: 1
|
101
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
102
|
+
# Configuration parameters: EnforcedStyle.
|
103
|
+
# SupportedStyles: literals, strict
|
104
|
+
Style/MutableConstant:
|
105
|
+
Exclude:
|
106
|
+
- "lib/grape_logging/version.rb"
|
107
|
+
|
108
|
+
# Offense count: 10
|
109
|
+
Style/OpenStructUse:
|
110
|
+
Exclude:
|
111
|
+
- "spec/lib/grape_logging/loggers/client_env_spec.rb"
|
112
|
+
- "spec/lib/grape_logging/loggers/filter_parameters_spec.rb"
|
113
|
+
- "spec/lib/grape_logging/loggers/request_headers_spec.rb"
|
114
|
+
- "spec/lib/grape_logging/loggers/response_spec.rb"
|
115
|
+
|
116
|
+
# Offense count: 3
|
117
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
118
|
+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
|
119
|
+
# AllowedMethods: present?, blank?, presence, try, try!
|
120
|
+
Style/SafeNavigation:
|
121
|
+
Exclude:
|
122
|
+
- "lib/grape_logging/formatters/rails.rb"
|
123
|
+
|
124
|
+
# Offense count: 1
|
125
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
126
|
+
Style/SlicingWithRange:
|
127
|
+
Exclude:
|
128
|
+
- "lib/grape_logging/loggers/request_headers.rb"
|
129
|
+
|
130
|
+
# Offense count: 1
|
131
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
132
|
+
# Configuration parameters: RequireEnglish, EnforcedStyle.
|
133
|
+
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
|
134
|
+
Style/SpecialGlobalVars:
|
135
|
+
Exclude:
|
136
|
+
- "spec/spec_helper.rb"
|
137
|
+
|
138
|
+
# Offense count: 3
|
139
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
140
|
+
# Configuration parameters: Mode.
|
141
|
+
Style/StringConcatenation:
|
142
|
+
Exclude:
|
143
|
+
- "lib/grape_logging/formatters/json.rb"
|
144
|
+
- "lib/grape_logging/formatters/lograge.rb"
|
145
|
+
- "lib/grape_logging/formatters/logstash.rb"
|
146
|
+
|
147
|
+
# Offense count: 1
|
148
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
149
|
+
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
|
150
|
+
# AllowedMethods: define_method
|
151
|
+
Style/SymbolProc:
|
152
|
+
Exclude:
|
153
|
+
- "lib/grape_logging/util/parameter_filter.rb"
|
154
|
+
|
155
|
+
# Offense count: 11
|
156
|
+
# This cop supports safe autocorrection (--autocorrect).
|
157
|
+
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
158
|
+
# URISchemes: http, https
|
159
|
+
Layout/LineLength:
|
160
|
+
Max: 203
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.0.0] - 2025-08-07
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
- [#93](https://github.com/aserafin/grape_logging/pull/93) RequestLogger middleware to handle Grape 2.4 breaking change - [@devsigner](https://github.com/devsigner) and [@samsonjs](https://github.com/samsonjs).
|
7
|
+
|
8
|
+
[3.0.0]: https://github.com/aserafin/grape_logging/compare/v2.1.1...v3.0.0
|
9
|
+
|
10
|
+
## [2.1.1] - 2025-07-09
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- [#92](https://github.com/aserafin/grape_logging/pull/92) Handle symbol param keys during filtering - [@samsonjs](https://github.com/samsonjs).
|
14
|
+
|
15
|
+
[2.1.1]: https://github.com/aserafin/grape_logging/compare/v2.1.0...v2.1.1
|
16
|
+
|
3
17
|
## [2.1.0] - 2025-07-09
|
4
18
|
|
5
|
-
|
19
|
+
### Added
|
6
20
|
- [#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
21
|
|
8
22
|
[2.1.0]: https://github.com/aserafin/grape_logging/compare/v2.0.0...v2.1.0
|
data/RELEASING.md
CHANGED
@@ -15,7 +15,7 @@ Check that the last build succeeded in [GitHub Actions](https://github.com/asera
|
|
15
15
|
|
16
16
|
### Update Changelog
|
17
17
|
|
18
|
-
Change "
|
18
|
+
Change "Unreleased" in [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md) to the new version and date:
|
19
19
|
|
20
20
|
```
|
21
21
|
## [1.8.5] - 2024-06-28
|
@@ -96,10 +96,12 @@ end
|
|
96
96
|
Add the next release to [CHANGELOG.md](https://github.com/aserafin/grape_logging/blob/master/CHANGELOG.md).
|
97
97
|
|
98
98
|
```
|
99
|
-
## [
|
99
|
+
## [1.8.6] - Unreleased
|
100
100
|
|
101
101
|
### Changed or Fixed or Added
|
102
102
|
- Your contribution here.
|
103
|
+
|
104
|
+
[1.8.6]: https://github.com/aserafin/grape_logging/compare/v1.8.5...master
|
103
105
|
```
|
104
106
|
|
105
107
|
Commit your changes.
|
data/Rakefile
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.rspec_opts = ['-fd -c']
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
11
|
+
t.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'Rakefile', 'Gemfile', 'grape_logging.gemspec']
|
12
|
+
end
|
5
13
|
|
6
|
-
task default:
|
14
|
+
task default: %i[spec rubocop]
|
7
15
|
|
8
16
|
desc 'Release gem and create GitHub release'
|
9
17
|
task github_release: :release do
|
@@ -14,9 +22,9 @@ task github_release: :release do
|
|
14
22
|
# Check if gh CLI is available
|
15
23
|
unless system('which gh > /dev/null 2>&1')
|
16
24
|
puts "\n⚠️ GitHub CLI (gh) not found"
|
17
|
-
puts
|
18
|
-
puts
|
19
|
-
puts
|
25
|
+
puts 'To create a GitHub release with auto-generated changelog, install gh:'
|
26
|
+
puts ' brew install gh # macOS with Homebrew'
|
27
|
+
puts ' # or visit: https://github.com/cli/cli#installation'
|
20
28
|
puts "\nYou can manually create the release with:"
|
21
29
|
puts " gh release create v#{GrapeLogging::VERSION} --generate-notes"
|
22
30
|
next
|
@@ -28,8 +36,8 @@ task github_release: :release do
|
|
28
36
|
if system('gh', 'release', 'create', version, '--generate-notes', '--verify-tag')
|
29
37
|
puts "✅ GitHub release #{version} created successfully"
|
30
38
|
else
|
31
|
-
puts
|
32
|
-
puts
|
39
|
+
puts '❌ Failed to create GitHub release'
|
40
|
+
puts 'You can manually create it with:'
|
33
41
|
puts " gh release create '#{version}' --generate-notes --verify-tag"
|
34
42
|
end
|
35
43
|
end
|
data/grape_logging.gemspec
CHANGED
@@ -1,26 +1,32 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'grape_logging/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'grape_logging'
|
7
7
|
spec.version = GrapeLogging::VERSION
|
8
|
-
spec.authors = ['aserafin']
|
9
|
-
spec.email = ['adrian@softmad.pl']
|
8
|
+
spec.authors = ['aserafin', 'Sami Samhuri']
|
9
|
+
spec.email = ['adrian@softmad.pl', 'sami@samhuri.net']
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'Out of the box request logging for Grape!'
|
12
|
+
spec.description = 'This gem provides simple request logging for Grape with just few lines ' \
|
13
|
+
'of code you have to put in your project! In return you will get response ' \
|
14
|
+
'codes, paths, parameters and more!'
|
13
15
|
spec.homepage = 'http://github.com/aserafin/grape_logging'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
|
16
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
21
|
spec.require_paths = ['lib']
|
20
22
|
|
21
|
-
spec.add_dependency 'grape', '
|
23
|
+
spec.add_dependency 'grape', '>= 2.4.0'
|
22
24
|
spec.add_dependency 'rack'
|
23
25
|
|
24
26
|
spec.add_development_dependency 'rake', '~> 13.3'
|
25
27
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
|
29
|
+
# This is pinned to an exact version otherwise we can't know which rules
|
30
|
+
# are in play at any given time in different environments.
|
31
|
+
spec.add_development_dependency 'rubocop', '1.77.0'
|
26
32
|
end
|
@@ -3,9 +3,9 @@ module GrapeLogging
|
|
3
3
|
class Logstash
|
4
4
|
def call(severity, datetime, _, data)
|
5
5
|
{
|
6
|
-
|
7
|
-
|
8
|
-
:
|
6
|
+
'@timestamp': datetime.iso8601,
|
7
|
+
'@version': '1',
|
8
|
+
severity: severity
|
9
9
|
}.merge!(format(data)).to_json + "\n"
|
10
10
|
end
|
11
11
|
|
@@ -3,7 +3,6 @@ require 'rack/utils'
|
|
3
3
|
module GrapeLogging
|
4
4
|
module Formatters
|
5
5
|
class Rails
|
6
|
-
|
7
6
|
def call(severity, datetime, _, data)
|
8
7
|
if data.is_a?(String)
|
9
8
|
"#{severity[0..0]} [#{datetime}] #{severity} -- : #{data}\n"
|
@@ -24,7 +23,7 @@ module GrapeLogging
|
|
24
23
|
[
|
25
24
|
"#{exception.message} (#{exception.class})",
|
26
25
|
backtrace_array.join("\n")
|
27
|
-
].reject{|line| line ==
|
26
|
+
].reject { |line| line == '' }.join("\n")
|
28
27
|
end
|
29
28
|
|
30
29
|
def format_hash(hash)
|
@@ -32,7 +31,7 @@ module GrapeLogging
|
|
32
31
|
# Completed 200 OK in 958ms (Views: 951.1ms | ActiveRecord: 3.8ms)
|
33
32
|
# See: actionpack/lib/action_controller/log_subscriber.rb
|
34
33
|
|
35
|
-
message =
|
34
|
+
message = ''
|
36
35
|
additions = []
|
37
36
|
status = hash.delete(:status)
|
38
37
|
params = hash.delete(:params)
|
@@ -47,13 +46,12 @@ module GrapeLogging
|
|
47
46
|
message << " Parameters: #{params.inspect}\n" if params
|
48
47
|
|
49
48
|
message << "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in #{total_time}ms"
|
50
|
-
message << " (#{additions.join(
|
49
|
+
message << " (#{additions.join(' | '.freeze)})" unless additions.empty?
|
51
50
|
message << "\n"
|
52
51
|
message << "\n" if defined?(::Rails.env) && ::Rails.env.development?
|
53
52
|
|
54
53
|
message
|
55
54
|
end
|
56
|
-
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -2,7 +2,7 @@ module GrapeLogging
|
|
2
2
|
module Loggers
|
3
3
|
class ClientEnv < GrapeLogging::Loggers::Base
|
4
4
|
def parameters(request, _)
|
5
|
-
{ ip: request.env[
|
5
|
+
{ ip: request.env['HTTP_X_FORWARDED_FOR'] || request.env['REMOTE_ADDR'], ua: request.env['HTTP_USER_AGENT'] }
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -3,7 +3,7 @@ module GrapeLogging
|
|
3
3
|
class FilterParameters < GrapeLogging::Loggers::Base
|
4
4
|
AD_PARAMS = 'action_dispatch.request.parameters'.freeze
|
5
5
|
|
6
|
-
def initialize(filter_parameters = nil, replacement = nil, exceptions = %w
|
6
|
+
def initialize(filter_parameters = nil, replacement = nil, exceptions = %w[controller action format])
|
7
7
|
@filter_parameters = filter_parameters || (defined?(::Rails.application) ? ::Rails.application.config.filter_parameters : [])
|
8
8
|
@replacement = replacement || '[FILTERED]'
|
9
9
|
@exceptions = exceptions
|
@@ -30,21 +30,23 @@ module GrapeLogging
|
|
30
30
|
|
31
31
|
def clean_parameters(parameters)
|
32
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) }
|
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
35
|
transform_key_encoding(cleaned_params, original_encoding_map)
|
36
36
|
end
|
37
37
|
|
38
38
|
def build_encoding_map(parameters)
|
39
39
|
parameters.each_with_object({}) do |(k, v), h|
|
40
|
-
|
40
|
+
key_str = k.to_s
|
41
|
+
h[key_str.dup.force_encoding(Encoding::ASCII_8BIT)] = [key_str.encoding, v.is_a?(Hash) ? build_encoding_map(v) : nil]
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
def transform_key_encoding(parameters, encoding_map)
|
45
46
|
parameters.each_with_object({}) do |(k, v), h|
|
46
|
-
|
47
|
-
|
47
|
+
key_str = k.to_s
|
48
|
+
encoding, children_encoding_map = encoding_map[key_str]
|
49
|
+
h[key_str.dup.force_encoding(encoding)] = v.is_a?(Hash) ? transform_key_encoding(v, children_encoding_map) : v
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module GrapeLogging
|
2
2
|
module Loggers
|
3
3
|
class RequestHeaders < GrapeLogging::Loggers::Base
|
4
|
-
|
5
4
|
HTTP_PREFIX = 'HTTP_'.freeze
|
6
5
|
|
7
6
|
def parameters(request, _)
|
@@ -16,7 +15,6 @@ module GrapeLogging
|
|
16
15
|
|
17
16
|
{ headers: headers }
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -11,12 +11,11 @@ module GrapeLogging
|
|
11
11
|
# For example, if you POST on a PUT endpoint, response.body is egal to """".
|
12
12
|
# It's strange, but it's the Grape behavior...
|
13
13
|
def serialized_response_body(response)
|
14
|
-
|
15
14
|
if response.respond_to?(:body)
|
16
15
|
# Rack responses
|
17
16
|
begin
|
18
|
-
response.body.map{ |body| JSON.parse(body.to_s) }
|
19
|
-
rescue # No reason to have "=> e" here when we don't use it..
|
17
|
+
response.body.map { |body| JSON.parse(body.to_s) }
|
18
|
+
rescue StandardError # No reason to have "=> e" here when we don't use it..
|
20
19
|
response.body
|
21
20
|
end
|
22
21
|
else
|
@@ -3,25 +3,27 @@ require 'grape'
|
|
3
3
|
module GrapeLogging
|
4
4
|
module Middleware
|
5
5
|
class RequestLogger < Grape::Middleware::Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
if defined?(ActiveRecord)
|
7
|
+
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
8
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
9
|
+
GrapeLogging::Timings.append_db_runtime(event)
|
10
|
+
end
|
11
|
+
end
|
11
12
|
|
12
13
|
# Persist response status & response (body)
|
13
14
|
# to use int in parameters
|
14
15
|
attr_accessor :response_status, :response_body
|
15
16
|
|
16
|
-
def initialize(app, options
|
17
|
+
def initialize(app, **options)
|
17
18
|
super
|
18
19
|
|
19
20
|
@included_loggers = @options[:include] || []
|
20
|
-
@reporter =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
@reporter =
|
22
|
+
if options[:instrumentation_key]
|
23
|
+
Reporters::ActiveSupportReporter.new(@options[:instrumentation_key])
|
24
|
+
else
|
25
|
+
Reporters::LoggerReporter.new(@options[:logger], @options[:formatter], @options[:log_level])
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def before
|
@@ -99,7 +101,7 @@ module GrapeLogging
|
|
99
101
|
path: request.path,
|
100
102
|
params: request.params,
|
101
103
|
host: request.host,
|
102
|
-
request_id: env['action_dispatch.request_id']
|
104
|
+
request_id: env['action_dispatch.request_id']
|
103
105
|
}
|
104
106
|
end
|
105
107
|
|
@@ -3,9 +3,7 @@ module Reporters
|
|
3
3
|
def initialize(logger, formatter, log_level)
|
4
4
|
@logger = logger.clone || Logger.new(STDOUT)
|
5
5
|
@log_level = log_level || :info
|
6
|
-
if @logger.respond_to?(:formatter=)
|
7
|
-
@logger.formatter = formatter || @logger.formatter || GrapeLogging::Formatters::Default.new
|
8
|
-
end
|
6
|
+
@logger.formatter = formatter || @logger.formatter || GrapeLogging::Formatters::Default.new if @logger.respond_to?(:formatter=)
|
9
7
|
end
|
10
8
|
|
11
9
|
def perform(params)
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module GrapeLogging
|
2
2
|
module Timings
|
3
|
-
|
4
|
-
|
5
|
-
def db_runtime=(value)
|
3
|
+
def self.db_runtime=(value)
|
6
4
|
Thread.current[:grape_db_runtime] = value
|
7
5
|
end
|
8
6
|
|
9
|
-
def db_runtime
|
7
|
+
def self.db_runtime
|
10
8
|
Thread.current[:grape_db_runtime] ||= 0
|
11
9
|
end
|
12
10
|
|
13
|
-
def reset_db_runtime
|
11
|
+
def self.reset_db_runtime
|
14
12
|
self.db_runtime = 0
|
15
13
|
end
|
16
14
|
|
17
|
-
def append_db_runtime(event)
|
15
|
+
def self.append_db_runtime(event)
|
18
16
|
self.db_runtime += event.duration
|
19
17
|
end
|
20
18
|
end
|
21
|
-
end
|
19
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
if defined?(
|
1
|
+
if defined?(Rails.application)
|
2
2
|
if Gem::Version.new(Rails.version) < Gem::Version.new('6.0.0')
|
3
3
|
class ParameterFilter < ActionDispatch::Http::ParameterFilter
|
4
4
|
def initialize(_replacement, filter_parameters)
|
@@ -6,7 +6,7 @@ if defined?(::Rails.application)
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
else
|
9
|
-
require
|
9
|
+
require 'active_support/parameter_filter'
|
10
10
|
|
11
11
|
class ParameterFilter < ActiveSupport::ParameterFilter
|
12
12
|
def initialize(_replacement, filter_parameters)
|
@@ -37,9 +37,11 @@ else
|
|
37
37
|
|
38
38
|
class CompiledFilter # :nodoc:
|
39
39
|
def self.compile(replacement, filters)
|
40
|
-
return
|
40
|
+
return ->(params) { params.dup } if filters.empty?
|
41
41
|
|
42
|
-
strings
|
42
|
+
strings = []
|
43
|
+
regexps = []
|
44
|
+
blocks = []
|
43
45
|
|
44
46
|
filters.each do |item|
|
45
47
|
case item
|
@@ -52,8 +54,8 @@ else
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
deep_regexps, regexps = regexps.partition { |r| r.to_s.include?(
|
56
|
-
deep_strings, strings = strings.partition { |s| s.include?(
|
57
|
+
deep_regexps, regexps = regexps.partition { |r| r.to_s.include?('\\.'.freeze) }
|
58
|
+
deep_strings, strings = strings.partition { |s| s.include?('\\.'.freeze) }
|
57
59
|
|
58
60
|
regexps << Regexp.new(strings.join('|'.freeze), true) unless strings.empty?
|
59
61
|
deep_regexps << Regexp.new(deep_strings.join('|'.freeze), true) unless deep_strings.empty?
|
@@ -67,7 +69,7 @@ else
|
|
67
69
|
@replacement = replacement
|
68
70
|
@regexps = regexps
|
69
71
|
@deep_regexps = deep_regexps.any? ? deep_regexps : nil
|
70
|
-
@blocks
|
72
|
+
@blocks = blocks
|
71
73
|
end
|
72
74
|
|
73
75
|
def call(original_params, parents = [])
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aserafin
|
8
|
+
- Sami Samhuri
|
8
9
|
bindir: exe
|
9
10
|
cert_chain: []
|
10
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
@@ -13,14 +14,14 @@ dependencies:
|
|
13
14
|
name: grape
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
|
-
- - "
|
17
|
+
- - ">="
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: 2.4.0
|
19
20
|
type: :runtime
|
20
21
|
prerelease: false
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
22
23
|
requirements:
|
23
|
-
- - "
|
24
|
+
- - ">="
|
24
25
|
- !ruby/object:Gem::Version
|
25
26
|
version: 2.4.0
|
26
27
|
- !ruby/object:Gem::Dependency
|
@@ -65,17 +66,34 @@ dependencies:
|
|
65
66
|
- - "~>"
|
66
67
|
- !ruby/object:Gem::Version
|
67
68
|
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.77.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.77.0
|
68
83
|
description: This gem provides simple request logging for Grape with just few lines
|
69
84
|
of code you have to put in your project! In return you will get response codes,
|
70
85
|
paths, parameters and more!
|
71
86
|
email:
|
72
87
|
- adrian@softmad.pl
|
88
|
+
- sami@samhuri.net
|
73
89
|
executables: []
|
74
90
|
extensions: []
|
75
91
|
extra_rdoc_files: []
|
76
92
|
files:
|
77
93
|
- ".github/workflows/ci.yml"
|
78
94
|
- ".gitignore"
|
95
|
+
- ".rubocop.yml"
|
96
|
+
- ".rubocop_todo.yml"
|
79
97
|
- CHANGELOG.md
|
80
98
|
- CONTRIBUTING.md
|
81
99
|
- Gemfile
|