pier_logging 0.2.5 → 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 +97 -85
- data/README.md +1 -0
- data/lib/pier_logging.rb +49 -9
- data/lib/pier_logging/helpers/redactor.rb +62 -0
- data/lib/pier_logging/logger.rb +13 -2
- data/lib/pier_logging/request_logger.rb +21 -58
- 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,144 +1,154 @@
|
|
|
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.
|
|
14
|
-
actionpack (= 6.
|
|
13
|
+
actioncable (6.1.3.2)
|
|
14
|
+
actionpack (= 6.1.3.2)
|
|
15
|
+
activesupport (= 6.1.3.2)
|
|
15
16
|
nio4r (~> 2.0)
|
|
16
17
|
websocket-driver (>= 0.6.1)
|
|
17
|
-
actionmailbox (6.
|
|
18
|
-
actionpack (= 6.
|
|
19
|
-
activejob (= 6.
|
|
20
|
-
activerecord (= 6.
|
|
21
|
-
activestorage (= 6.
|
|
22
|
-
activesupport (= 6.
|
|
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)
|
|
23
24
|
mail (>= 2.7.1)
|
|
24
|
-
actionmailer (6.
|
|
25
|
-
actionpack (= 6.
|
|
26
|
-
actionview (= 6.
|
|
27
|
-
activejob (= 6.
|
|
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)
|
|
28
30
|
mail (~> 2.5, >= 2.5.4)
|
|
29
31
|
rails-dom-testing (~> 2.0)
|
|
30
|
-
actionpack (6.
|
|
31
|
-
actionview (= 6.
|
|
32
|
-
activesupport (= 6.
|
|
33
|
-
rack (~> 2.0, >= 2.0.
|
|
32
|
+
actionpack (6.1.3.2)
|
|
33
|
+
actionview (= 6.1.3.2)
|
|
34
|
+
activesupport (= 6.1.3.2)
|
|
35
|
+
rack (~> 2.0, >= 2.0.9)
|
|
34
36
|
rack-test (>= 0.6.3)
|
|
35
37
|
rails-dom-testing (~> 2.0)
|
|
36
38
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
37
|
-
actiontext (6.
|
|
38
|
-
actionpack (= 6.
|
|
39
|
-
activerecord (= 6.
|
|
40
|
-
activestorage (= 6.
|
|
41
|
-
activesupport (= 6.
|
|
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)
|
|
42
44
|
nokogiri (>= 1.8.5)
|
|
43
|
-
actionview (6.
|
|
44
|
-
activesupport (= 6.
|
|
45
|
+
actionview (6.1.3.2)
|
|
46
|
+
activesupport (= 6.1.3.2)
|
|
45
47
|
builder (~> 3.1)
|
|
46
48
|
erubi (~> 1.4)
|
|
47
49
|
rails-dom-testing (~> 2.0)
|
|
48
50
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
49
|
-
activejob (6.
|
|
50
|
-
activesupport (= 6.
|
|
51
|
+
activejob (6.1.3.2)
|
|
52
|
+
activesupport (= 6.1.3.2)
|
|
51
53
|
globalid (>= 0.3.6)
|
|
52
|
-
activemodel (6.
|
|
53
|
-
activesupport (= 6.
|
|
54
|
-
activerecord (6.
|
|
55
|
-
activemodel (= 6.
|
|
56
|
-
activesupport (= 6.
|
|
57
|
-
activestorage (6.
|
|
58
|
-
actionpack (= 6.
|
|
59
|
-
activejob (= 6.
|
|
60
|
-
activerecord (= 6.
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
marcel (~> 1.0.0)
|
|
65
|
+
mini_mime (~> 1.0.2)
|
|
66
|
+
activesupport (6.1.3.2)
|
|
63
67
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
64
|
-
i18n (>=
|
|
65
|
-
minitest (
|
|
66
|
-
tzinfo (~>
|
|
67
|
-
zeitwerk (~> 2.
|
|
68
|
-
|
|
68
|
+
i18n (>= 1.6, < 2)
|
|
69
|
+
minitest (>= 5.1)
|
|
70
|
+
tzinfo (~> 2.0)
|
|
71
|
+
zeitwerk (~> 2.3)
|
|
72
|
+
amazing_print (1.3.0)
|
|
69
73
|
builder (3.2.4)
|
|
70
74
|
byebug (11.1.3)
|
|
71
|
-
concurrent-ruby (1.1.
|
|
75
|
+
concurrent-ruby (1.1.8)
|
|
72
76
|
crass (1.0.6)
|
|
73
|
-
erubi (1.
|
|
77
|
+
erubi (1.10.0)
|
|
74
78
|
facets (3.1.0)
|
|
75
79
|
globalid (0.4.2)
|
|
76
80
|
activesupport (>= 4.2.0)
|
|
77
|
-
i18n (1.8.
|
|
81
|
+
i18n (1.8.10)
|
|
78
82
|
concurrent-ruby (~> 1.0)
|
|
79
|
-
loofah (2.
|
|
83
|
+
loofah (2.9.1)
|
|
80
84
|
crass (~> 1.0.2)
|
|
81
85
|
nokogiri (>= 1.5.9)
|
|
82
86
|
mail (2.7.1)
|
|
83
87
|
mini_mime (>= 0.1.1)
|
|
84
|
-
marcel (0.
|
|
85
|
-
mimemagic (~> 0.3.2)
|
|
88
|
+
marcel (1.0.1)
|
|
86
89
|
method_source (1.0.0)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
nio4r (2.5.
|
|
92
|
-
nokogiri (1.
|
|
93
|
-
mini_portile2 (~> 2.
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
mini_mime (1.0.3)
|
|
91
|
+
mini_portile2 (2.5.1)
|
|
92
|
+
minitest (5.14.4)
|
|
93
|
+
mocha (1.12.0)
|
|
94
|
+
nio4r (2.5.7)
|
|
95
|
+
nokogiri (1.11.6)
|
|
96
|
+
mini_portile2 (~> 2.5.0)
|
|
97
|
+
racc (~> 1.4)
|
|
98
|
+
oj (3.11.5)
|
|
99
|
+
ougai (2.0.0)
|
|
96
100
|
oj (~> 3.10)
|
|
101
|
+
racc (1.5.2)
|
|
97
102
|
rack (2.2.3)
|
|
98
103
|
rack-test (1.1.0)
|
|
99
104
|
rack (>= 1.0, < 3)
|
|
100
|
-
rails (6.
|
|
101
|
-
actioncable (= 6.
|
|
102
|
-
actionmailbox (= 6.
|
|
103
|
-
actionmailer (= 6.
|
|
104
|
-
actionpack (= 6.
|
|
105
|
-
actiontext (= 6.
|
|
106
|
-
actionview (= 6.
|
|
107
|
-
activejob (= 6.
|
|
108
|
-
activemodel (= 6.
|
|
109
|
-
activerecord (= 6.
|
|
110
|
-
activestorage (= 6.
|
|
111
|
-
activesupport (= 6.
|
|
112
|
-
bundler (>= 1.
|
|
113
|
-
railties (= 6.
|
|
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)
|
|
117
|
+
bundler (>= 1.15.0)
|
|
118
|
+
railties (= 6.1.3.2)
|
|
114
119
|
sprockets-rails (>= 2.0.0)
|
|
115
120
|
rails-dom-testing (2.0.3)
|
|
116
121
|
activesupport (>= 4.2.0)
|
|
117
122
|
nokogiri (>= 1.6)
|
|
118
123
|
rails-html-sanitizer (1.3.0)
|
|
119
124
|
loofah (~> 2.3)
|
|
120
|
-
railties (6.
|
|
121
|
-
actionpack (= 6.
|
|
122
|
-
activesupport (= 6.
|
|
125
|
+
railties (6.1.3.2)
|
|
126
|
+
actionpack (= 6.1.3.2)
|
|
127
|
+
activesupport (= 6.1.3.2)
|
|
123
128
|
method_source
|
|
124
129
|
rake (>= 0.8.7)
|
|
125
|
-
thor (
|
|
126
|
-
rake (13.0.
|
|
130
|
+
thor (~> 1.0)
|
|
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)
|
|
127
138
|
sprockets (4.0.2)
|
|
128
139
|
concurrent-ruby (~> 1.0)
|
|
129
140
|
rack (> 1, < 3)
|
|
130
|
-
sprockets-rails (3.2.
|
|
141
|
+
sprockets-rails (3.2.2)
|
|
131
142
|
actionpack (>= 4.0)
|
|
132
143
|
activesupport (>= 4.0)
|
|
133
144
|
sprockets (>= 3.0.0)
|
|
134
|
-
thor (1.0
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
websocket-driver (0.7.2)
|
|
145
|
+
thor (1.1.0)
|
|
146
|
+
tzinfo (2.0.4)
|
|
147
|
+
concurrent-ruby (~> 1.0)
|
|
148
|
+
websocket-driver (0.7.4)
|
|
139
149
|
websocket-extensions (>= 0.1.0)
|
|
140
150
|
websocket-extensions (0.1.5)
|
|
141
|
-
zeitwerk (2.
|
|
151
|
+
zeitwerk (2.4.2)
|
|
142
152
|
|
|
143
153
|
PLATFORMS
|
|
144
154
|
ruby
|
|
@@ -147,8 +157,10 @@ DEPENDENCIES
|
|
|
147
157
|
bundler (>= 2.1.4)
|
|
148
158
|
byebug (>= 11.1.3)
|
|
149
159
|
minitest (>= 5.8.4)
|
|
160
|
+
mocha
|
|
150
161
|
pier_logging!
|
|
151
162
|
rake (>= 12.3.3)
|
|
163
|
+
shoulda (= 4.0.0.rc2)
|
|
152
164
|
|
|
153
165
|
BUNDLED WITH
|
|
154
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,19 +53,33 @@ 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_response_body_for_paths,
|
|
58
|
-
:log_response, :hide_request_headers, :correlation_id_getter
|
|
70
|
+
attr_reader :enabled, :user_info_getter, :hide_request_body_for_paths, :hide_response_body_for_paths,
|
|
71
|
+
:log_request_body, :log_response, :hide_request_headers, :correlation_id_getter
|
|
59
72
|
|
|
60
73
|
def initialize
|
|
61
74
|
@user_info_getter = ->(_ = nil) { nil }
|
|
62
75
|
@enabled = false
|
|
76
|
+
@hide_request_body_for_paths = nil
|
|
63
77
|
@hide_response_body_for_paths = nil
|
|
78
|
+
@log_request_body = true
|
|
64
79
|
@log_response = true
|
|
65
80
|
@hide_request_headers = nil
|
|
66
81
|
@correlation_id_getter = ->(_ = nil, _ = nil) { nil }
|
|
82
|
+
@sensitive_keywords = []
|
|
67
83
|
end
|
|
68
84
|
|
|
69
85
|
def user_info_getter=(proc)
|
|
@@ -71,26 +87,39 @@ module PierLogging
|
|
|
71
87
|
@user_info_getter = proc
|
|
72
88
|
end
|
|
73
89
|
|
|
90
|
+
def log_request_body=(log_request_body)
|
|
91
|
+
raise ArgumentError, "Config 'log_request_body' must be a 'boolean'" unless !!log_request_body == log_request_body
|
|
92
|
+
@log_request_body = log_request_body
|
|
93
|
+
end
|
|
94
|
+
|
|
74
95
|
def log_response=(log_response)
|
|
75
96
|
raise ArgumentError, "Config 'log_response' must be a 'boolean'" unless !!log_response == log_response
|
|
76
97
|
@log_response = log_response
|
|
77
98
|
end
|
|
78
99
|
|
|
100
|
+
def hide_request_body_for_paths=(hide_request_body_for_paths)
|
|
101
|
+
unless (hide_request_body_for_paths.is_a? Array) && (hide_request_body_for_paths.all?{|item| item.is_a? Regexp})
|
|
102
|
+
raise ArgumentError, "Config 'hide_request_body_for_paths' must be an 'Array of Regexps'"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
@hide_request_body_for_paths = hide_request_body_for_paths
|
|
106
|
+
end
|
|
107
|
+
|
|
79
108
|
def hide_response_body_for_paths=(hide_response_body_for_paths)
|
|
80
109
|
unless (hide_response_body_for_paths.is_a? Array) && (hide_response_body_for_paths.all?{|item| item.is_a? Regexp})
|
|
81
|
-
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'"
|
|
82
111
|
end
|
|
83
|
-
|
|
112
|
+
|
|
84
113
|
@hide_response_body_for_paths = hide_response_body_for_paths
|
|
85
114
|
end
|
|
86
115
|
|
|
87
116
|
def hide_request_headers=(hide_request_headers)
|
|
88
117
|
unless (hide_request_headers.is_a? Array) && (hide_request_headers.all?{|item| item.is_a? Regexp})
|
|
89
|
-
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'"
|
|
90
119
|
end
|
|
91
120
|
@hide_request_headers = hide_request_headers
|
|
92
121
|
end
|
|
93
|
-
|
|
122
|
+
|
|
94
123
|
def enabled=(enabled = false)
|
|
95
124
|
raise ArgumentError, "Config 'enabled' must be a 'boolean'" unless !!enabled == enabled
|
|
96
125
|
@enabled = enabled
|
|
@@ -100,5 +129,16 @@ module PierLogging
|
|
|
100
129
|
raise ArgumentError, "Config 'correlation_id_getter' must be a 'Proc'" unless proc.is_a? Proc
|
|
101
130
|
@correlation_id_getter = proc
|
|
102
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
|
|
103
143
|
end
|
|
104
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
module PierLogging
|
|
3
3
|
class Logger < Ougai::Logger
|
|
4
4
|
include ActiveSupport::LoggerThreadSafeLevel
|
|
5
|
-
include LoggerSilence
|
|
5
|
+
include ActiveSupport::LoggerSilence if defined?(ActiveSupport::LoggerSilence)
|
|
6
6
|
|
|
7
7
|
def initialize(*args)
|
|
8
8
|
super
|
|
@@ -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,
|
|
@@ -57,44 +43,54 @@ module PierLogging
|
|
|
57
43
|
headers: request_headers,
|
|
58
44
|
href: request.url,
|
|
59
45
|
query_string: request.query_string,
|
|
60
|
-
body:
|
|
46
|
+
body: request_body(request.path, request.body)
|
|
61
47
|
},
|
|
62
48
|
response: {
|
|
63
49
|
status: status,
|
|
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
|
|
85
72
|
|
|
73
|
+
def request_body(request_path, body)
|
|
74
|
+
return nil unless PierLogging.request_logger_configuration.log_request_body
|
|
75
|
+
|
|
76
|
+
hide_request_body_for_paths = PierLogging.request_logger_configuration.hide_request_body_for_paths
|
|
77
|
+
return nil if hide_request_body_for_paths&.any?{ |path|request_path =~ path }
|
|
78
|
+
|
|
79
|
+
parse_body(body)
|
|
80
|
+
end
|
|
81
|
+
|
|
86
82
|
def response_body(request_path, body)
|
|
87
83
|
return nil unless PierLogging.request_logger_configuration.log_response
|
|
88
|
-
|
|
84
|
+
|
|
89
85
|
hide_response_body_for_paths = PierLogging.request_logger_configuration.hide_response_body_for_paths
|
|
90
|
-
return nil if hide_response_body_for_paths
|
|
91
|
-
|
|
86
|
+
return nil if hide_response_body_for_paths&.any?{ |path|request_path =~ path }
|
|
87
|
+
|
|
92
88
|
parse_body(body)
|
|
93
89
|
end
|
|
94
90
|
|
|
95
91
|
def build_message_from_request(request)
|
|
96
92
|
[
|
|
97
|
-
request.request_method.upcase,
|
|
93
|
+
request.request_method.upcase,
|
|
98
94
|
[request.base_url,request.path].join(''),
|
|
99
95
|
].join(' ')
|
|
100
96
|
end
|
|
@@ -120,39 +116,6 @@ module PierLogging
|
|
|
120
116
|
body
|
|
121
117
|
end
|
|
122
118
|
|
|
123
|
-
def redact_object(obj, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
|
124
|
-
if obj === Array
|
|
125
|
-
redact_array(obj, replace_keys, replace_by)
|
|
126
|
-
elsif obj === Hash
|
|
127
|
-
redact_hash(obj, replace_keys, replace_by)
|
|
128
|
-
elsif obj.respond_to?(:to_hash)
|
|
129
|
-
redact_hash(obj.to_hash, replace_keys, replace_by)
|
|
130
|
-
else
|
|
131
|
-
obj
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def redact_array(arr, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
|
136
|
-
raise StandardError, 'Could not redact_array for non-array objects' unless arr.is_a? Array
|
|
137
|
-
arr.map { |el| redact_object(el, replace_keys, replace_by) }
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def redact_hash(hash, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
|
|
141
|
-
raise StandardError, 'Could not redact_hash for non-hash objects' unless hash.is_a? Hash
|
|
142
|
-
hash.traverse do |k,v|
|
|
143
|
-
should_redact = replace_keys.any?{ |regex| k =~regex }
|
|
144
|
-
if (should_redact)
|
|
145
|
-
[k, replace_by]
|
|
146
|
-
else
|
|
147
|
-
case v
|
|
148
|
-
when Array then [k, redact_array(v, replace_keys, replace_by)]
|
|
149
|
-
else
|
|
150
|
-
[k, v]
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
119
|
def determine_body_from_exception(exception)
|
|
157
120
|
{ message: exception.message }
|
|
158
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:
|
|
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
|