pier_logging 0.3.3 → 0.4.1
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/.gitignore +2 -1
- data/Gemfile.lock +70 -61
- data/README.md +1 -0
- data/lib/pier_logging.rb +35 -10
- data/lib/pier_logging/helpers/redactor.rb +62 -0
- data/lib/pier_logging/logger.rb +12 -1
- data/lib/pier_logging/request_logger.rb +11 -57
- data/lib/pier_logging/version.rb +1 -1
- data/pier_logging.gemspec +6 -4
- metadata +40 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e0c321ad52cca238c2d9b3b608b477d4f60c2b5ca217b4e78bebe97ad3effa
|
4
|
+
data.tar.gz: 4b5bdad78b8a2b1e4e38556d1d379a794b5b892648eb45a9a1b08c2d41dfb130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1e928bcaadc7580ead5c0620e633943de3e6808c28143094572fa204ec7db1ea55a0dd315d03dcbb460a7d48a796830cdd5cfd767c018e954ef42020ae73e2
|
7
|
+
data.tar.gz: f210951495a2f64446e8316a77c4e928b1a0042af17fc9d33b6d26c402b6af42855bb304d451cf78d6fce03662d6ab5c353440bc56b0416b036b1f535a28bdc7
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,75 +1,75 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pier_logging (0.
|
5
|
-
|
4
|
+
pier_logging (0.4.0)
|
5
|
+
amazing_print
|
6
6
|
facets
|
7
|
-
ougai
|
7
|
+
ougai (>= 2.0.0)
|
8
8
|
rails
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (6.1.3.
|
14
|
-
actionpack (= 6.1.3.
|
15
|
-
activesupport (= 6.1.3.
|
13
|
+
actioncable (6.1.3.2)
|
14
|
+
actionpack (= 6.1.3.2)
|
15
|
+
activesupport (= 6.1.3.2)
|
16
16
|
nio4r (~> 2.0)
|
17
17
|
websocket-driver (>= 0.6.1)
|
18
|
-
actionmailbox (6.1.3.
|
19
|
-
actionpack (= 6.1.3.
|
20
|
-
activejob (= 6.1.3.
|
21
|
-
activerecord (= 6.1.3.
|
22
|
-
activestorage (= 6.1.3.
|
23
|
-
activesupport (= 6.1.3.
|
18
|
+
actionmailbox (6.1.3.2)
|
19
|
+
actionpack (= 6.1.3.2)
|
20
|
+
activejob (= 6.1.3.2)
|
21
|
+
activerecord (= 6.1.3.2)
|
22
|
+
activestorage (= 6.1.3.2)
|
23
|
+
activesupport (= 6.1.3.2)
|
24
24
|
mail (>= 2.7.1)
|
25
|
-
actionmailer (6.1.3.
|
26
|
-
actionpack (= 6.1.3.
|
27
|
-
actionview (= 6.1.3.
|
28
|
-
activejob (= 6.1.3.
|
29
|
-
activesupport (= 6.1.3.
|
25
|
+
actionmailer (6.1.3.2)
|
26
|
+
actionpack (= 6.1.3.2)
|
27
|
+
actionview (= 6.1.3.2)
|
28
|
+
activejob (= 6.1.3.2)
|
29
|
+
activesupport (= 6.1.3.2)
|
30
30
|
mail (~> 2.5, >= 2.5.4)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
|
-
actionpack (6.1.3.
|
33
|
-
actionview (= 6.1.3.
|
34
|
-
activesupport (= 6.1.3.
|
32
|
+
actionpack (6.1.3.2)
|
33
|
+
actionview (= 6.1.3.2)
|
34
|
+
activesupport (= 6.1.3.2)
|
35
35
|
rack (~> 2.0, >= 2.0.9)
|
36
36
|
rack-test (>= 0.6.3)
|
37
37
|
rails-dom-testing (~> 2.0)
|
38
38
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
39
|
-
actiontext (6.1.3.
|
40
|
-
actionpack (= 6.1.3.
|
41
|
-
activerecord (= 6.1.3.
|
42
|
-
activestorage (= 6.1.3.
|
43
|
-
activesupport (= 6.1.3.
|
39
|
+
actiontext (6.1.3.2)
|
40
|
+
actionpack (= 6.1.3.2)
|
41
|
+
activerecord (= 6.1.3.2)
|
42
|
+
activestorage (= 6.1.3.2)
|
43
|
+
activesupport (= 6.1.3.2)
|
44
44
|
nokogiri (>= 1.8.5)
|
45
|
-
actionview (6.1.3.
|
46
|
-
activesupport (= 6.1.3.
|
45
|
+
actionview (6.1.3.2)
|
46
|
+
activesupport (= 6.1.3.2)
|
47
47
|
builder (~> 3.1)
|
48
48
|
erubi (~> 1.4)
|
49
49
|
rails-dom-testing (~> 2.0)
|
50
50
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
51
|
-
activejob (6.1.3.
|
52
|
-
activesupport (= 6.1.3.
|
51
|
+
activejob (6.1.3.2)
|
52
|
+
activesupport (= 6.1.3.2)
|
53
53
|
globalid (>= 0.3.6)
|
54
|
-
activemodel (6.1.3.
|
55
|
-
activesupport (= 6.1.3.
|
56
|
-
activerecord (6.1.3.
|
57
|
-
activemodel (= 6.1.3.
|
58
|
-
activesupport (= 6.1.3.
|
59
|
-
activestorage (6.1.3.
|
60
|
-
actionpack (= 6.1.3.
|
61
|
-
activejob (= 6.1.3.
|
62
|
-
activerecord (= 6.1.3.
|
63
|
-
activesupport (= 6.1.3.
|
54
|
+
activemodel (6.1.3.2)
|
55
|
+
activesupport (= 6.1.3.2)
|
56
|
+
activerecord (6.1.3.2)
|
57
|
+
activemodel (= 6.1.3.2)
|
58
|
+
activesupport (= 6.1.3.2)
|
59
|
+
activestorage (6.1.3.2)
|
60
|
+
actionpack (= 6.1.3.2)
|
61
|
+
activejob (= 6.1.3.2)
|
62
|
+
activerecord (= 6.1.3.2)
|
63
|
+
activesupport (= 6.1.3.2)
|
64
64
|
marcel (~> 1.0.0)
|
65
65
|
mini_mime (~> 1.0.2)
|
66
|
-
activesupport (6.1.3.
|
66
|
+
activesupport (6.1.3.2)
|
67
67
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
68
68
|
i18n (>= 1.6, < 2)
|
69
69
|
minitest (>= 5.1)
|
70
70
|
tzinfo (~> 2.0)
|
71
71
|
zeitwerk (~> 2.3)
|
72
|
-
|
72
|
+
amazing_print (1.3.0)
|
73
73
|
builder (3.2.4)
|
74
74
|
byebug (11.1.3)
|
75
75
|
concurrent-ruby (1.1.8)
|
@@ -88,46 +88,53 @@ GEM
|
|
88
88
|
marcel (1.0.1)
|
89
89
|
method_source (1.0.0)
|
90
90
|
mini_mime (1.0.3)
|
91
|
-
mini_portile2 (2.5.
|
91
|
+
mini_portile2 (2.5.1)
|
92
92
|
minitest (5.14.4)
|
93
|
+
mocha (1.12.0)
|
93
94
|
nio4r (2.5.7)
|
94
|
-
nokogiri (1.11.
|
95
|
+
nokogiri (1.11.6)
|
95
96
|
mini_portile2 (~> 2.5.0)
|
96
97
|
racc (~> 1.4)
|
97
|
-
oj (3.11.
|
98
|
+
oj (3.11.5)
|
98
99
|
ougai (2.0.0)
|
99
100
|
oj (~> 3.10)
|
100
101
|
racc (1.5.2)
|
101
102
|
rack (2.2.3)
|
102
103
|
rack-test (1.1.0)
|
103
104
|
rack (>= 1.0, < 3)
|
104
|
-
rails (6.1.3.
|
105
|
-
actioncable (= 6.1.3.
|
106
|
-
actionmailbox (= 6.1.3.
|
107
|
-
actionmailer (= 6.1.3.
|
108
|
-
actionpack (= 6.1.3.
|
109
|
-
actiontext (= 6.1.3.
|
110
|
-
actionview (= 6.1.3.
|
111
|
-
activejob (= 6.1.3.
|
112
|
-
activemodel (= 6.1.3.
|
113
|
-
activerecord (= 6.1.3.
|
114
|
-
activestorage (= 6.1.3.
|
115
|
-
activesupport (= 6.1.3.
|
105
|
+
rails (6.1.3.2)
|
106
|
+
actioncable (= 6.1.3.2)
|
107
|
+
actionmailbox (= 6.1.3.2)
|
108
|
+
actionmailer (= 6.1.3.2)
|
109
|
+
actionpack (= 6.1.3.2)
|
110
|
+
actiontext (= 6.1.3.2)
|
111
|
+
actionview (= 6.1.3.2)
|
112
|
+
activejob (= 6.1.3.2)
|
113
|
+
activemodel (= 6.1.3.2)
|
114
|
+
activerecord (= 6.1.3.2)
|
115
|
+
activestorage (= 6.1.3.2)
|
116
|
+
activesupport (= 6.1.3.2)
|
116
117
|
bundler (>= 1.15.0)
|
117
|
-
railties (= 6.1.3.
|
118
|
+
railties (= 6.1.3.2)
|
118
119
|
sprockets-rails (>= 2.0.0)
|
119
120
|
rails-dom-testing (2.0.3)
|
120
121
|
activesupport (>= 4.2.0)
|
121
122
|
nokogiri (>= 1.6)
|
122
123
|
rails-html-sanitizer (1.3.0)
|
123
124
|
loofah (~> 2.3)
|
124
|
-
railties (6.1.3.
|
125
|
-
actionpack (= 6.1.3.
|
126
|
-
activesupport (= 6.1.3.
|
125
|
+
railties (6.1.3.2)
|
126
|
+
actionpack (= 6.1.3.2)
|
127
|
+
activesupport (= 6.1.3.2)
|
127
128
|
method_source
|
128
129
|
rake (>= 0.8.7)
|
129
130
|
thor (~> 1.0)
|
130
131
|
rake (13.0.3)
|
132
|
+
shoulda (4.0.0.rc2)
|
133
|
+
shoulda-context (= 2.0.0.rc4)
|
134
|
+
shoulda-matchers (~> 4.0)
|
135
|
+
shoulda-context (2.0.0.rc4)
|
136
|
+
shoulda-matchers (4.5.1)
|
137
|
+
activesupport (>= 4.2.0)
|
131
138
|
sprockets (4.0.2)
|
132
139
|
concurrent-ruby (~> 1.0)
|
133
140
|
rack (> 1, < 3)
|
@@ -138,7 +145,7 @@ GEM
|
|
138
145
|
thor (1.1.0)
|
139
146
|
tzinfo (2.0.4)
|
140
147
|
concurrent-ruby (~> 1.0)
|
141
|
-
websocket-driver (0.7.
|
148
|
+
websocket-driver (0.7.4)
|
142
149
|
websocket-extensions (>= 0.1.0)
|
143
150
|
websocket-extensions (0.1.5)
|
144
151
|
zeitwerk (2.4.2)
|
@@ -150,8 +157,10 @@ DEPENDENCIES
|
|
150
157
|
bundler (>= 2.1.4)
|
151
158
|
byebug (>= 11.1.3)
|
152
159
|
minitest (>= 5.8.4)
|
160
|
+
mocha
|
153
161
|
pier_logging!
|
154
162
|
rake (>= 12.3.3)
|
163
|
+
shoulda (= 4.0.0.rc2)
|
155
164
|
|
156
165
|
BUNDLED WITH
|
157
166
|
2.1.4
|
data/README.md
CHANGED
@@ -42,6 +42,7 @@ Use `PierLogging.configure_request_logger` block to configure request logs. Acce
|
|
42
42
|
| ---------------- | --------:| ---------------:| ----------:|
|
43
43
|
| enabled | false | boolean | false |
|
44
44
|
| user_info_getter | true | block (headers) | nil |
|
45
|
+
| sensitive_keywords | false | array of symbols, strings or regexps | `REDACT_REPLACE_KEYS` in request_logger.rb
|
45
46
|
|
46
47
|
The block passed to `user_info_getter` receives the headers of the request so you can use your headers to define the username or role.
|
47
48
|
|
data/lib/pier_logging.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "ougai"
|
3
|
-
require "
|
3
|
+
require "amazing_print"
|
4
4
|
require "facets/hash/traverse"
|
5
5
|
require "pier_logging/version"
|
6
6
|
require "pier_logging/logger"
|
@@ -10,6 +10,7 @@ require "pier_logging/formatter/json"
|
|
10
10
|
require "pier_logging/formatter/readable"
|
11
11
|
require "pier_logging/helpers/headers"
|
12
12
|
require "pier_logging/helpers/env_config"
|
13
|
+
require "pier_logging/helpers/redactor"
|
13
14
|
|
14
15
|
module PierLogging
|
15
16
|
def self.logger_configuration
|
@@ -29,19 +30,20 @@ module PierLogging
|
|
29
30
|
end
|
30
31
|
|
31
32
|
class LoggerConfiguration
|
32
|
-
attr_reader :app_name, :env, :formatter
|
33
|
+
attr_reader :app_name, :env, :formatter, :sensitive_keywords
|
33
34
|
|
34
35
|
def initialize
|
35
36
|
@app_name = nil
|
36
37
|
@env = nil
|
37
38
|
@formatter = Formatter::Json.new
|
39
|
+
@sensitive_keywords = []
|
38
40
|
end
|
39
41
|
|
40
42
|
def app_name=(app_name)
|
41
43
|
raise ArgumentError, "Config 'app_name' must be a String" unless app_name.is_a?(String)
|
42
44
|
@app_name = app_name
|
43
45
|
end
|
44
|
-
|
46
|
+
|
45
47
|
def env=(env)
|
46
48
|
raise ArgumentError, "Config 'env' must be a String" unless env.is_a?(String)
|
47
49
|
@env = env
|
@@ -51,10 +53,21 @@ module PierLogging
|
|
51
53
|
raise ArgumentError, "Config 'formatter' must be a 'Ougai::Formatters::Base'" unless formatter.is_a?(Ougai::Formatters::Base)
|
52
54
|
@formatter = formatter
|
53
55
|
end
|
56
|
+
|
57
|
+
def sensitive_keywords=(keywords)
|
58
|
+
keywords.map! do |kw|
|
59
|
+
if kw.is_a? Regexp
|
60
|
+
kw
|
61
|
+
else
|
62
|
+
Regexp.new(kw.to_s)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@sensitive_keywords += keywords
|
66
|
+
end
|
54
67
|
end
|
55
68
|
|
56
69
|
class RequestLoggerConfiguration
|
57
|
-
attr_reader :enabled, :user_info_getter, :hide_request_body_for_paths, :hide_response_body_for_paths,
|
70
|
+
attr_reader :enabled, :user_info_getter, :hide_request_body_for_paths, :hide_response_body_for_paths,
|
58
71
|
:log_request_body, :log_response, :hide_request_headers, :correlation_id_getter
|
59
72
|
|
60
73
|
def initialize
|
@@ -66,6 +79,7 @@ module PierLogging
|
|
66
79
|
@log_response = true
|
67
80
|
@hide_request_headers = nil
|
68
81
|
@correlation_id_getter = ->(_ = nil, _ = nil) { nil }
|
82
|
+
@sensitive_keywords = []
|
69
83
|
end
|
70
84
|
|
71
85
|
def user_info_getter=(proc)
|
@@ -85,27 +99,27 @@ module PierLogging
|
|
85
99
|
|
86
100
|
def hide_request_body_for_paths=(hide_request_body_for_paths)
|
87
101
|
unless (hide_request_body_for_paths.is_a? Array) && (hide_request_body_for_paths.all?{|item| item.is_a? Regexp})
|
88
|
-
raise ArgumentError, "Config 'hide_request_body_for_paths' must be an 'Array of Regexps'"
|
102
|
+
raise ArgumentError, "Config 'hide_request_body_for_paths' must be an 'Array of Regexps'"
|
89
103
|
end
|
90
|
-
|
104
|
+
|
91
105
|
@hide_request_body_for_paths = hide_request_body_for_paths
|
92
106
|
end
|
93
107
|
|
94
108
|
def hide_response_body_for_paths=(hide_response_body_for_paths)
|
95
109
|
unless (hide_response_body_for_paths.is_a? Array) && (hide_response_body_for_paths.all?{|item| item.is_a? Regexp})
|
96
|
-
raise ArgumentError, "Config 'hide_response_body_for_paths' must be an 'Array of Regexps'"
|
110
|
+
raise ArgumentError, "Config 'hide_response_body_for_paths' must be an 'Array of Regexps'"
|
97
111
|
end
|
98
|
-
|
112
|
+
|
99
113
|
@hide_response_body_for_paths = hide_response_body_for_paths
|
100
114
|
end
|
101
115
|
|
102
116
|
def hide_request_headers=(hide_request_headers)
|
103
117
|
unless (hide_request_headers.is_a? Array) && (hide_request_headers.all?{|item| item.is_a? Regexp})
|
104
|
-
raise ArgumentError, "Config 'hide_request_headers' must be an 'Array of Regexps'"
|
118
|
+
raise ArgumentError, "Config 'hide_request_headers' must be an 'Array of Regexps'"
|
105
119
|
end
|
106
120
|
@hide_request_headers = hide_request_headers
|
107
121
|
end
|
108
|
-
|
122
|
+
|
109
123
|
def enabled=(enabled = false)
|
110
124
|
raise ArgumentError, "Config 'enabled' must be a 'boolean'" unless !!enabled == enabled
|
111
125
|
@enabled = enabled
|
@@ -115,5 +129,16 @@ module PierLogging
|
|
115
129
|
raise ArgumentError, "Config 'correlation_id_getter' must be a 'Proc'" unless proc.is_a? Proc
|
116
130
|
@correlation_id_getter = proc
|
117
131
|
end
|
132
|
+
|
133
|
+
def sensitive_keywords=(keywords)
|
134
|
+
keywords.map! do |kw|
|
135
|
+
if kw.is_a? Regexp
|
136
|
+
kw
|
137
|
+
else
|
138
|
+
Regexp.new(kw.to_s)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
@sensitive_keywords += keywords
|
142
|
+
end
|
118
143
|
end
|
119
144
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Requiring only the part that we need
|
2
|
+
require 'facets/hash/traverse'
|
3
|
+
|
4
|
+
module PierLogging
|
5
|
+
module Helpers
|
6
|
+
class Redactor
|
7
|
+
REDACT_REPLACE_KEYS = [
|
8
|
+
/passw(or)?d/i,
|
9
|
+
/^pw$/,
|
10
|
+
/^pass$/i,
|
11
|
+
/secret/i,
|
12
|
+
/token/i,
|
13
|
+
/api[-._]?key/i,
|
14
|
+
/session[-._]?id/i,
|
15
|
+
/^connect\.sid$/
|
16
|
+
].freeze
|
17
|
+
REDACT_REPLACE_BY = '*'.freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def redact(obj, replace_keys = nil, replace_by = REDACT_REPLACE_BY)
|
21
|
+
replace_keys ||= sensitive_keywords
|
22
|
+
if obj.is_a?(Array)
|
23
|
+
redact_array(obj, replace_keys, replace_by)
|
24
|
+
elsif obj.is_a?(Hash)
|
25
|
+
redact_hash(obj, replace_keys, replace_by)
|
26
|
+
elsif obj.respond_to?(:to_hash)
|
27
|
+
redact_hash(obj.to_hash, replace_keys, replace_by)
|
28
|
+
else
|
29
|
+
obj
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def sensitive_keywords
|
36
|
+
REDACT_REPLACE_KEYS + PierLogging.logger_configuration.sensitive_keywords
|
37
|
+
end
|
38
|
+
|
39
|
+
def redact_array(arr, replace_keys, replace_by = REDACT_REPLACE_BY)
|
40
|
+
raise StandardError, 'Could not redact_array for non-array objects' unless arr.is_a? Array
|
41
|
+
arr.map { |el| redact(el, replace_keys, replace_by) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def redact_hash(hash, replace_keys, replace_by = REDACT_REPLACE_BY)
|
45
|
+
raise StandardError, 'Could not redact_hash for non-hash objects' unless hash.is_a? Hash
|
46
|
+
hash.traverse do |k,v|
|
47
|
+
should_redact = replace_keys.any?{ |regex| k =~ regex }
|
48
|
+
if (should_redact)
|
49
|
+
[k, replace_by]
|
50
|
+
else
|
51
|
+
case v
|
52
|
+
when Array then [k, redact_array(v, replace_keys, replace_by)]
|
53
|
+
else
|
54
|
+
[k, v]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/pier_logging/logger.rb
CHANGED
@@ -12,5 +12,16 @@ module PierLogging
|
|
12
12
|
def create_formatter
|
13
13
|
PierLogging.logger_configuration.formatter
|
14
14
|
end
|
15
|
+
|
16
|
+
def _log(severity, *args)
|
17
|
+
redacted_args = redact_data(args)
|
18
|
+
super(severity, *redacted_args)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def redact_data(data)
|
24
|
+
PierLogging::Helpers::Redactor.redact(data)
|
25
|
+
end
|
15
26
|
end
|
16
|
-
end
|
27
|
+
end
|
@@ -1,19 +1,5 @@
|
|
1
|
-
# Requiring only the part that we need
|
2
|
-
require 'facets/hash/traverse'
|
3
1
|
module PierLogging
|
4
2
|
class RequestLogger
|
5
|
-
REDACT_REPLACE_KEYS = [
|
6
|
-
/passw(or)?d/i,
|
7
|
-
/^pw$/,
|
8
|
-
/^pass$/i,
|
9
|
-
/secret/i,
|
10
|
-
/token/i,
|
11
|
-
/api[-._]?key/i,
|
12
|
-
/session[-._]?id/i,
|
13
|
-
/^connect\.sid$/
|
14
|
-
].freeze
|
15
|
-
REDACT_REPLACE_BY = '*'.freeze
|
16
|
-
|
17
3
|
attr_reader :logger
|
18
4
|
|
19
5
|
def initialize(app, logger = PierLogging::Logger.new(STDOUT))
|
@@ -44,7 +30,7 @@ module PierLogging
|
|
44
30
|
env, status, type, body, starts_at, ends_at, _ = args
|
45
31
|
request = Rack::Request.new(env)
|
46
32
|
request_headers = get_request_headers_from_env(env)
|
47
|
-
|
33
|
+
info = {
|
48
34
|
message: build_message_from_request(request),
|
49
35
|
type: 'http',
|
50
36
|
duration: ((ends_at - starts_at)*1000).to_i,
|
@@ -64,21 +50,22 @@ module PierLogging
|
|
64
50
|
body: response_body(request.path, body),
|
65
51
|
type: type['Content-Type'],
|
66
52
|
}
|
67
|
-
}
|
53
|
+
}
|
54
|
+
logger.info info
|
68
55
|
rescue StandardError => error
|
69
56
|
# We should never fall in this part as the only errors that could result in this are errors
|
70
57
|
# in our logger (inside this same method)
|
71
58
|
@logger.error(error.message)
|
72
|
-
end
|
59
|
+
end
|
73
60
|
|
74
61
|
private
|
75
62
|
def get_request_headers_from_env(env)
|
76
63
|
hide_request_headers = PierLogging.request_logger_configuration.hide_request_headers
|
77
|
-
|
64
|
+
|
78
65
|
headers = env.select { |k,v| k[0..4] == 'HTTP_'}.
|
79
66
|
transform_keys { |k| k[5..-1].split('_').join('-').upcase }
|
80
|
-
|
81
|
-
return
|
67
|
+
|
68
|
+
return PierLogging::Helpers::Redactor.redact(headers, hide_request_headers, nil) if hide_request_headers.present?
|
82
69
|
|
83
70
|
headers
|
84
71
|
end
|
@@ -91,19 +78,19 @@ module PierLogging
|
|
91
78
|
|
92
79
|
parse_body(body)
|
93
80
|
end
|
94
|
-
|
81
|
+
|
95
82
|
def response_body(request_path, body)
|
96
83
|
return nil unless PierLogging.request_logger_configuration.log_response
|
97
|
-
|
84
|
+
|
98
85
|
hide_response_body_for_paths = PierLogging.request_logger_configuration.hide_response_body_for_paths
|
99
86
|
return nil if hide_response_body_for_paths&.any?{ |path|request_path =~ path }
|
100
|
-
|
87
|
+
|
101
88
|
parse_body(body)
|
102
89
|
end
|
103
90
|
|
104
91
|
def build_message_from_request(request)
|
105
92
|
[
|
106
|
-
request.request_method.upcase,
|
93
|
+
request.request_method.upcase,
|
107
94
|
[request.base_url,request.path].join(''),
|
108
95
|
].join(' ')
|
109
96
|
end
|
@@ -129,39 +116,6 @@ module PierLogging
|
|
129
116
|
body
|
130
117
|
end
|
131
118
|
|
132
|
-
def redact_object(obj, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
133
|
-
if obj === Array
|
134
|
-
redact_array(obj, replace_keys, replace_by)
|
135
|
-
elsif obj === Hash
|
136
|
-
redact_hash(obj, replace_keys, replace_by)
|
137
|
-
elsif obj.respond_to?(:to_hash)
|
138
|
-
redact_hash(obj.to_hash, replace_keys, replace_by)
|
139
|
-
else
|
140
|
-
obj
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def redact_array(arr, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
145
|
-
raise StandardError, 'Could not redact_array for non-array objects' unless arr.is_a? Array
|
146
|
-
arr.map { |el| redact_object(el, replace_keys, replace_by) }
|
147
|
-
end
|
148
|
-
|
149
|
-
def redact_hash(hash, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
150
|
-
raise StandardError, 'Could not redact_hash for non-hash objects' unless hash.is_a? Hash
|
151
|
-
hash.traverse do |k,v|
|
152
|
-
should_redact = replace_keys.any?{ |regex| k =~regex }
|
153
|
-
if (should_redact)
|
154
|
-
[k, replace_by]
|
155
|
-
else
|
156
|
-
case v
|
157
|
-
when Array then [k, redact_array(v, replace_keys, replace_by)]
|
158
|
-
else
|
159
|
-
[k, v]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
119
|
def determine_body_from_exception(exception)
|
166
120
|
{ message: exception.message }
|
167
121
|
end
|
data/lib/pier_logging/version.rb
CHANGED
data/pier_logging.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "pier_logging/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "pier_logging"
|
8
8
|
spec.version = PierLogging::VERSION
|
9
|
-
spec.authors = ["Mauricio Banduk"]
|
10
|
-
spec.email = ["mauricio.banduk@pier.digital"]
|
9
|
+
spec.authors = ["Mauricio Banduk", "Bruno Arakaki", "Leonardo Bighetti", "Tiago Macedo"]
|
10
|
+
spec.email = ["mauricio.banduk@pier.digital", "bruno.arakaki@pier.digital", "leonardo.bighetti@pier.digital", "tiago.macedo@pier.digital"]
|
11
11
|
|
12
12
|
spec.summary = %q{Structured log used on Pier Applications}
|
13
13
|
spec.description = %q{Defines a basic structure for general and request logging}
|
@@ -23,11 +23,13 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_dependency "ougai"
|
27
|
-
spec.add_dependency "
|
26
|
+
spec.add_dependency "ougai", ">=2.0.0"
|
27
|
+
spec.add_dependency "amazing_print"
|
28
28
|
spec.add_dependency "rails"
|
29
29
|
spec.add_dependency "facets"
|
30
30
|
|
31
|
+
spec.add_development_dependency "shoulda", "4.0.0.rc2"
|
32
|
+
spec.add_development_dependency "mocha"
|
31
33
|
spec.add_development_dependency "bundler", ">= 2.1.4"
|
32
34
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
33
35
|
spec.add_development_dependency "minitest", ">= 5.8.4"
|
metadata
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pier_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Banduk
|
8
|
+
- Bruno Arakaki
|
9
|
+
- Leonardo Bighetti
|
10
|
+
- Tiago Macedo
|
8
11
|
autorequire:
|
9
12
|
bindir: exe
|
10
13
|
cert_chain: []
|
11
|
-
date: 2021-
|
14
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
17
|
name: ougai
|
@@ -16,16 +19,16 @@ dependencies:
|
|
16
19
|
requirements:
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 2.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 2.0.0
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
31
|
+
name: amazing_print
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
30
33
|
requirements:
|
31
34
|
- - ">="
|
@@ -66,6 +69,34 @@ dependencies:
|
|
66
69
|
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: shoulda
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 4.0.0.rc2
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 4.0.0.rc2
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: mocha
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
69
100
|
- !ruby/object:Gem::Dependency
|
70
101
|
name: bundler
|
71
102
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +156,9 @@ dependencies:
|
|
125
156
|
description: Defines a basic structure for general and request logging
|
126
157
|
email:
|
127
158
|
- mauricio.banduk@pier.digital
|
159
|
+
- bruno.arakaki@pier.digital
|
160
|
+
- leonardo.bighetti@pier.digital
|
161
|
+
- tiago.macedo@pier.digital
|
128
162
|
executables: []
|
129
163
|
extensions: []
|
130
164
|
extra_rdoc_files: []
|
@@ -151,6 +185,7 @@ files:
|
|
151
185
|
- lib/pier_logging/formatter/readable.rb
|
152
186
|
- lib/pier_logging/helpers/env_config.rb
|
153
187
|
- lib/pier_logging/helpers/headers.rb
|
188
|
+
- lib/pier_logging/helpers/redactor.rb
|
154
189
|
- lib/pier_logging/logger.rb
|
155
190
|
- lib/pier_logging/request_logger.rb
|
156
191
|
- lib/pier_logging/version.rb
|