pier_logging 0.3.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04659db491f4230e2dcc6bb313fe9f9ca4b9563c0b4b705bc61777112eb52327'
4
- data.tar.gz: ee82d54e3ff4bc24a2ad78b7d42f78cc3c2fe031a9c93c349981e959eebcc4d0
3
+ metadata.gz: ac877e591e45d88a090eb520bf1cc5f729376899614dfc222a05c8c3ae197421
4
+ data.tar.gz: 96ceee22c036f05962dc83eb7af822b0ee37651cde402782bbf5f40b036ad6f1
5
5
  SHA512:
6
- metadata.gz: 8dd5860cfe2b8ca25b8218a4f934cd828d35c1efbf776ebd40e0e34eaf8e2726b32ebc9da108e278068acf5a1b66831869f6f7342731454ed27ae19f8d06a822
7
- data.tar.gz: bec737e90c8c6e41cd121409a4a2df80a187ef509a2c7b3bce9580c8e024ff3cff509fc5462892ad487cebf1f3682335072c403fb0516007847272bed3d6767a
6
+ metadata.gz: 6750d36a6e30c0196d62acce35298a98182eba15c70e89e2f323fcb9e6d7ed75289cdb86c305b00dab21cfb11bc005d8236bc86f8ea9a9cf45f6c1febf064897
7
+ data.tar.gz: 51e799f43aa706aa24f81a869a8d35eec859e2df95adb331da1e1ccb1a031f94afee6aad56161583621f008a0ed9921a7157467f4489524350e793c57687956b
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- *.gem
9
+ *.gem
10
+ .byebug_history
data/Gemfile.lock CHANGED
@@ -1,135 +1,140 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pier_logging (0.3.0)
5
- awesome_print
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.1)
14
- actionpack (= 6.1.1)
15
- activesupport (= 6.1.1)
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.1)
19
- actionpack (= 6.1.1)
20
- activejob (= 6.1.1)
21
- activerecord (= 6.1.1)
22
- activestorage (= 6.1.1)
23
- activesupport (= 6.1.1)
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.1)
26
- actionpack (= 6.1.1)
27
- actionview (= 6.1.1)
28
- activejob (= 6.1.1)
29
- activesupport (= 6.1.1)
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.1)
33
- actionview (= 6.1.1)
34
- activesupport (= 6.1.1)
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.1)
40
- actionpack (= 6.1.1)
41
- activerecord (= 6.1.1)
42
- activestorage (= 6.1.1)
43
- activesupport (= 6.1.1)
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.1)
46
- activesupport (= 6.1.1)
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.1)
52
- activesupport (= 6.1.1)
51
+ activejob (6.1.3.2)
52
+ activesupport (= 6.1.3.2)
53
53
  globalid (>= 0.3.6)
54
- activemodel (6.1.1)
55
- activesupport (= 6.1.1)
56
- activerecord (6.1.1)
57
- activemodel (= 6.1.1)
58
- activesupport (= 6.1.1)
59
- activestorage (6.1.1)
60
- actionpack (= 6.1.1)
61
- activejob (= 6.1.1)
62
- activerecord (= 6.1.1)
63
- activesupport (= 6.1.1)
64
- marcel (~> 0.3.1)
65
- mimemagic (~> 0.3.2)
66
- activesupport (6.1.1)
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)
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
- awesome_print (1.8.0)
72
+ amazing_print (1.3.0)
73
73
  builder (3.2.4)
74
74
  byebug (11.1.3)
75
- concurrent-ruby (1.1.7)
75
+ concurrent-ruby (1.1.8)
76
76
  crass (1.0.6)
77
77
  erubi (1.10.0)
78
78
  facets (3.1.0)
79
79
  globalid (0.4.2)
80
80
  activesupport (>= 4.2.0)
81
- i18n (1.8.7)
81
+ i18n (1.8.10)
82
82
  concurrent-ruby (~> 1.0)
83
- loofah (2.8.0)
83
+ loofah (2.9.1)
84
84
  crass (~> 1.0.2)
85
85
  nokogiri (>= 1.5.9)
86
86
  mail (2.7.1)
87
87
  mini_mime (>= 0.1.1)
88
- marcel (0.3.3)
89
- mimemagic (~> 0.3.2)
88
+ marcel (1.0.1)
90
89
  method_source (1.0.0)
91
- mimemagic (0.3.5)
92
- mini_mime (1.0.2)
93
- mini_portile2 (2.5.0)
94
- minitest (5.14.1)
95
- nio4r (2.5.4)
96
- nokogiri (1.11.1)
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)
97
96
  mini_portile2 (~> 2.5.0)
98
97
  racc (~> 1.4)
99
- oj (3.10.18)
100
- ougai (1.8.5)
98
+ oj (3.11.5)
99
+ ougai (2.0.0)
101
100
  oj (~> 3.10)
102
101
  racc (1.5.2)
103
102
  rack (2.2.3)
104
103
  rack-test (1.1.0)
105
104
  rack (>= 1.0, < 3)
106
- rails (6.1.1)
107
- actioncable (= 6.1.1)
108
- actionmailbox (= 6.1.1)
109
- actionmailer (= 6.1.1)
110
- actionpack (= 6.1.1)
111
- actiontext (= 6.1.1)
112
- actionview (= 6.1.1)
113
- activejob (= 6.1.1)
114
- activemodel (= 6.1.1)
115
- activerecord (= 6.1.1)
116
- activestorage (= 6.1.1)
117
- activesupport (= 6.1.1)
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)
118
117
  bundler (>= 1.15.0)
119
- railties (= 6.1.1)
118
+ railties (= 6.1.3.2)
120
119
  sprockets-rails (>= 2.0.0)
121
120
  rails-dom-testing (2.0.3)
122
121
  activesupport (>= 4.2.0)
123
122
  nokogiri (>= 1.6)
124
123
  rails-html-sanitizer (1.3.0)
125
124
  loofah (~> 2.3)
126
- railties (6.1.1)
127
- actionpack (= 6.1.1)
128
- activesupport (= 6.1.1)
125
+ railties (6.1.3.2)
126
+ actionpack (= 6.1.3.2)
127
+ activesupport (= 6.1.3.2)
129
128
  method_source
130
129
  rake (>= 0.8.7)
131
130
  thor (~> 1.0)
132
- rake (13.0.1)
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)
133
138
  sprockets (4.0.2)
134
139
  concurrent-ruby (~> 1.0)
135
140
  rack (> 1, < 3)
@@ -137,10 +142,10 @@ GEM
137
142
  actionpack (>= 4.0)
138
143
  activesupport (>= 4.0)
139
144
  sprockets (>= 3.0.0)
140
- thor (1.0.1)
145
+ thor (1.1.0)
141
146
  tzinfo (2.0.4)
142
147
  concurrent-ruby (~> 1.0)
143
- websocket-driver (0.7.3)
148
+ websocket-driver (0.7.4)
144
149
  websocket-extensions (>= 0.1.0)
145
150
  websocket-extensions (0.1.5)
146
151
  zeitwerk (2.4.2)
@@ -152,8 +157,10 @@ DEPENDENCIES
152
157
  bundler (>= 2.1.4)
153
158
  byebug (>= 11.1.3)
154
159
  minitest (>= 5.8.4)
160
+ mocha
155
161
  pier_logging!
156
162
  rake (>= 12.3.3)
163
+ shoulda (= 4.0.0.rc2)
157
164
 
158
165
  BUNDLED WITH
159
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
 
@@ -0,0 +1,63 @@
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
+ /authorization/i
17
+ ].freeze
18
+ REDACT_REPLACE_BY = '*'.freeze
19
+
20
+ class << self
21
+ def redact(obj, replace_keys = nil, replace_by = REDACT_REPLACE_BY)
22
+ replace_keys ||= sensitive_keywords
23
+ if obj.is_a?(Array)
24
+ redact_array(obj, replace_keys, replace_by)
25
+ elsif obj.is_a?(Hash)
26
+ redact_hash(obj, replace_keys, replace_by)
27
+ elsif obj.respond_to?(:to_hash)
28
+ redact_hash(obj.to_hash, replace_keys, replace_by)
29
+ else
30
+ obj
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def sensitive_keywords
37
+ REDACT_REPLACE_KEYS + PierLogging.logger_configuration.sensitive_keywords
38
+ end
39
+
40
+ def redact_array(arr, replace_keys, replace_by = REDACT_REPLACE_BY)
41
+ raise StandardError, 'Could not redact_array for non-array objects' unless arr.is_a? Array
42
+ arr.map { |el| redact(el, replace_keys, replace_by) }
43
+ end
44
+
45
+ def redact_hash(hash, replace_keys, replace_by = REDACT_REPLACE_BY)
46
+ raise StandardError, 'Could not redact_hash for non-hash objects' unless hash.is_a? Hash
47
+ hash.traverse do |k,v|
48
+ should_redact = replace_keys.any?{ |regex| k =~ regex }
49
+ if (should_redact)
50
+ [k, replace_by]
51
+ else
52
+ case v
53
+ when Array then [k, redact_array(v, replace_keys, replace_by)]
54
+ else
55
+ [k, v]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -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
- logger.info redact_object({
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: parse_body(request.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 redact_object(headers, hide_request_headers, nil) if hide_request_headers.present?
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 && hide_response_body_for_paths.any?{ |path|request_path =~ path }
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
@@ -1,3 +1,3 @@
1
1
  module PierLogging
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/pier_logging.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "rails"
2
2
  require "ougai"
3
- require "awesome_print"
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
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 "awesome_print"
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.3.1
4
+ version: 0.4.2
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-01-08 00:00:00.000000000 Z
14
+ date: 2021-12-16 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: '0'
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: '0'
29
+ version: 2.0.0
27
30
  - !ruby/object:Gem::Dependency
28
- name: awesome_print
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