pier_logging 0.2.4 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a68a14c994124359699bf1e907d76b47f06efe6f46d20bc2d68a13180b76ada8
4
- data.tar.gz: 671bc7adb48ffb3d33e694c17b7dcd68f6a1743220bcd22ba74f7c9f933efa18
3
+ metadata.gz: a55ccf237c0b0f40cdc5a97c3b1409112de8343a8b1070f1b70d814ef4ed4dad
4
+ data.tar.gz: acd0969b17612d4f42d1c8229699c5176e2aa8ebfdf13a5fd8c07b64b94602d3
5
5
  SHA512:
6
- metadata.gz: 72a2b35a68c812a341bf59dd24360ec0ed7b381f0873cc1d492e5507e4d7a7e527fe42f1d0b190afd8fcba3ca53a0e77bbc665bee224facb5c7abe2aa870962a
7
- data.tar.gz: 4fdb6ae38a9aa3d68d7437e34f2264f44e2721d3dab531a04236a169e6ff471987fd40fecb8cadc4e1b2c156158ee275e19a0a05ff4b33f0729e397c464cd532
6
+ metadata.gz: 56f1b5ca14007773f0604a3bf8720f81f5950892120e260a9a7c6a9231680edf4ece11c5702714e29a07ccae6c9490d8b406a992c78af8e6c1e85a887fa05deb
7
+ data.tar.gz: 79c17490ba3109bdbce3a06dd8fa45f92b6537a350e274273d5856208b99f878e9d085d4d194f7c8b62490af5b051b568d1a9eb74552993bb55c0962815a92d0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pier_logging (0.1.7)
4
+ pier_logging (0.3.1)
5
5
  awesome_print
6
6
  facets
7
7
  ougai
@@ -10,135 +10,138 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (6.0.3.2)
14
- actionpack (= 6.0.3.2)
13
+ actioncable (6.1.3.1)
14
+ actionpack (= 6.1.3.1)
15
+ activesupport (= 6.1.3.1)
15
16
  nio4r (~> 2.0)
16
17
  websocket-driver (>= 0.6.1)
17
- actionmailbox (6.0.3.2)
18
- actionpack (= 6.0.3.2)
19
- activejob (= 6.0.3.2)
20
- activerecord (= 6.0.3.2)
21
- activestorage (= 6.0.3.2)
22
- activesupport (= 6.0.3.2)
18
+ actionmailbox (6.1.3.1)
19
+ actionpack (= 6.1.3.1)
20
+ activejob (= 6.1.3.1)
21
+ activerecord (= 6.1.3.1)
22
+ activestorage (= 6.1.3.1)
23
+ activesupport (= 6.1.3.1)
23
24
  mail (>= 2.7.1)
24
- actionmailer (6.0.3.2)
25
- actionpack (= 6.0.3.2)
26
- actionview (= 6.0.3.2)
27
- activejob (= 6.0.3.2)
25
+ actionmailer (6.1.3.1)
26
+ actionpack (= 6.1.3.1)
27
+ actionview (= 6.1.3.1)
28
+ activejob (= 6.1.3.1)
29
+ activesupport (= 6.1.3.1)
28
30
  mail (~> 2.5, >= 2.5.4)
29
31
  rails-dom-testing (~> 2.0)
30
- actionpack (6.0.3.2)
31
- actionview (= 6.0.3.2)
32
- activesupport (= 6.0.3.2)
33
- rack (~> 2.0, >= 2.0.8)
32
+ actionpack (6.1.3.1)
33
+ actionview (= 6.1.3.1)
34
+ activesupport (= 6.1.3.1)
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.0.3.2)
38
- actionpack (= 6.0.3.2)
39
- activerecord (= 6.0.3.2)
40
- activestorage (= 6.0.3.2)
41
- activesupport (= 6.0.3.2)
39
+ actiontext (6.1.3.1)
40
+ actionpack (= 6.1.3.1)
41
+ activerecord (= 6.1.3.1)
42
+ activestorage (= 6.1.3.1)
43
+ activesupport (= 6.1.3.1)
42
44
  nokogiri (>= 1.8.5)
43
- actionview (6.0.3.2)
44
- activesupport (= 6.0.3.2)
45
+ actionview (6.1.3.1)
46
+ activesupport (= 6.1.3.1)
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.0.3.2)
50
- activesupport (= 6.0.3.2)
51
+ activejob (6.1.3.1)
52
+ activesupport (= 6.1.3.1)
51
53
  globalid (>= 0.3.6)
52
- activemodel (6.0.3.2)
53
- activesupport (= 6.0.3.2)
54
- activerecord (6.0.3.2)
55
- activemodel (= 6.0.3.2)
56
- activesupport (= 6.0.3.2)
57
- activestorage (6.0.3.2)
58
- actionpack (= 6.0.3.2)
59
- activejob (= 6.0.3.2)
60
- activerecord (= 6.0.3.2)
61
- marcel (~> 0.3.1)
62
- activesupport (6.0.3.2)
54
+ activemodel (6.1.3.1)
55
+ activesupport (= 6.1.3.1)
56
+ activerecord (6.1.3.1)
57
+ activemodel (= 6.1.3.1)
58
+ activesupport (= 6.1.3.1)
59
+ activestorage (6.1.3.1)
60
+ actionpack (= 6.1.3.1)
61
+ activejob (= 6.1.3.1)
62
+ activerecord (= 6.1.3.1)
63
+ activesupport (= 6.1.3.1)
64
+ marcel (~> 1.0.0)
65
+ mini_mime (~> 1.0.2)
66
+ activesupport (6.1.3.1)
63
67
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
- i18n (>= 0.7, < 2)
65
- minitest (~> 5.1)
66
- tzinfo (~> 1.1)
67
- zeitwerk (~> 2.2, >= 2.2.2)
68
- awesome_print (1.8.0)
68
+ i18n (>= 1.6, < 2)
69
+ minitest (>= 5.1)
70
+ tzinfo (~> 2.0)
71
+ zeitwerk (~> 2.3)
72
+ awesome_print (1.9.2)
69
73
  builder (3.2.4)
70
74
  byebug (11.1.3)
71
- concurrent-ruby (1.1.6)
75
+ concurrent-ruby (1.1.8)
72
76
  crass (1.0.6)
73
- erubi (1.9.0)
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.3)
81
+ i18n (1.8.10)
78
82
  concurrent-ruby (~> 1.0)
79
- loofah (2.6.0)
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.3.3)
85
- mimemagic (~> 0.3.2)
88
+ marcel (1.0.1)
86
89
  method_source (1.0.0)
87
- mimemagic (0.3.5)
88
- mini_mime (1.0.2)
89
- mini_portile2 (2.4.0)
90
- minitest (5.14.1)
91
- nio4r (2.5.2)
92
- nokogiri (1.10.9)
93
- mini_portile2 (~> 2.4.0)
94
- oj (3.10.6)
95
- ougai (1.8.5)
90
+ mini_mime (1.0.3)
91
+ mini_portile2 (2.5.0)
92
+ minitest (5.14.4)
93
+ nio4r (2.5.7)
94
+ nokogiri (1.11.3)
95
+ mini_portile2 (~> 2.5.0)
96
+ racc (~> 1.4)
97
+ oj (3.11.3)
98
+ ougai (2.0.0)
96
99
  oj (~> 3.10)
100
+ racc (1.5.2)
97
101
  rack (2.2.3)
98
102
  rack-test (1.1.0)
99
103
  rack (>= 1.0, < 3)
100
- rails (6.0.3.2)
101
- actioncable (= 6.0.3.2)
102
- actionmailbox (= 6.0.3.2)
103
- actionmailer (= 6.0.3.2)
104
- actionpack (= 6.0.3.2)
105
- actiontext (= 6.0.3.2)
106
- actionview (= 6.0.3.2)
107
- activejob (= 6.0.3.2)
108
- activemodel (= 6.0.3.2)
109
- activerecord (= 6.0.3.2)
110
- activestorage (= 6.0.3.2)
111
- activesupport (= 6.0.3.2)
112
- bundler (>= 1.3.0)
113
- railties (= 6.0.3.2)
104
+ rails (6.1.3.1)
105
+ actioncable (= 6.1.3.1)
106
+ actionmailbox (= 6.1.3.1)
107
+ actionmailer (= 6.1.3.1)
108
+ actionpack (= 6.1.3.1)
109
+ actiontext (= 6.1.3.1)
110
+ actionview (= 6.1.3.1)
111
+ activejob (= 6.1.3.1)
112
+ activemodel (= 6.1.3.1)
113
+ activerecord (= 6.1.3.1)
114
+ activestorage (= 6.1.3.1)
115
+ activesupport (= 6.1.3.1)
116
+ bundler (>= 1.15.0)
117
+ railties (= 6.1.3.1)
114
118
  sprockets-rails (>= 2.0.0)
115
119
  rails-dom-testing (2.0.3)
116
120
  activesupport (>= 4.2.0)
117
121
  nokogiri (>= 1.6)
118
122
  rails-html-sanitizer (1.3.0)
119
123
  loofah (~> 2.3)
120
- railties (6.0.3.2)
121
- actionpack (= 6.0.3.2)
122
- activesupport (= 6.0.3.2)
124
+ railties (6.1.3.1)
125
+ actionpack (= 6.1.3.1)
126
+ activesupport (= 6.1.3.1)
123
127
  method_source
124
128
  rake (>= 0.8.7)
125
- thor (>= 0.20.3, < 2.0)
126
- rake (13.0.1)
129
+ thor (~> 1.0)
130
+ rake (13.0.3)
127
131
  sprockets (4.0.2)
128
132
  concurrent-ruby (~> 1.0)
129
133
  rack (> 1, < 3)
130
- sprockets-rails (3.2.1)
134
+ sprockets-rails (3.2.2)
131
135
  actionpack (>= 4.0)
132
136
  activesupport (>= 4.0)
133
137
  sprockets (>= 3.0.0)
134
- thor (1.0.1)
135
- thread_safe (0.3.6)
136
- tzinfo (1.2.7)
137
- thread_safe (~> 0.1)
138
- websocket-driver (0.7.2)
138
+ thor (1.1.0)
139
+ tzinfo (2.0.4)
140
+ concurrent-ruby (~> 1.0)
141
+ websocket-driver (0.7.3)
139
142
  websocket-extensions (>= 0.1.0)
140
143
  websocket-extensions (0.1.5)
141
- zeitwerk (2.3.1)
144
+ zeitwerk (2.4.2)
142
145
 
143
146
  PLATFORMS
144
147
  ruby
data/lib/pier_logging.rb CHANGED
@@ -54,13 +54,15 @@ module PierLogging
54
54
  end
55
55
 
56
56
  class RequestLoggerConfiguration
57
- attr_reader :enabled, :user_info_getter, :hide_response_body_for_paths,
58
- :log_response, :hide_request_headers, :correlation_id_getter
57
+ attr_reader :enabled, :user_info_getter, :hide_request_body_for_paths, :hide_response_body_for_paths,
58
+ :log_request_body, :log_response, :hide_request_headers, :correlation_id_getter
59
59
 
60
60
  def initialize
61
61
  @user_info_getter = ->(_ = nil) { nil }
62
62
  @enabled = false
63
+ @hide_request_body_for_paths = nil
63
64
  @hide_response_body_for_paths = nil
65
+ @log_request_body = true
64
66
  @log_response = true
65
67
  @hide_request_headers = nil
66
68
  @correlation_id_getter = ->(_ = nil, _ = nil) { nil }
@@ -71,11 +73,24 @@ module PierLogging
71
73
  @user_info_getter = proc
72
74
  end
73
75
 
76
+ def log_request_body=(log_request_body)
77
+ raise ArgumentError, "Config 'log_request_body' must be a 'boolean'" unless !!log_request_body == log_request_body
78
+ @log_request_body = log_request_body
79
+ end
80
+
74
81
  def log_response=(log_response)
75
82
  raise ArgumentError, "Config 'log_response' must be a 'boolean'" unless !!log_response == log_response
76
83
  @log_response = log_response
77
84
  end
78
85
 
86
+ def hide_request_body_for_paths=(hide_request_body_for_paths)
87
+ 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'"
89
+ end
90
+
91
+ @hide_request_body_for_paths = hide_request_body_for_paths
92
+ end
93
+
79
94
  def hide_response_body_for_paths=(hide_response_body_for_paths)
80
95
  unless (hide_response_body_for_paths.is_a? Array) && (hide_response_body_for_paths.all?{|item| item.is_a? Regexp})
81
96
  raise ArgumentError, "Config 'hide_response_body_for_paths' must be an 'Array of Regexps'"
@@ -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
@@ -44,7 +44,7 @@ module PierLogging
44
44
  env, status, type, body, starts_at, ends_at, _ = args
45
45
  request = Rack::Request.new(env)
46
46
  request_headers = get_request_headers_from_env(env)
47
- logger.info redact_hash({
47
+ logger.info redact_object({
48
48
  message: build_message_from_request(request),
49
49
  type: 'http',
50
50
  duration: ((ends_at - starts_at)*1000).to_i,
@@ -56,7 +56,8 @@ module PierLogging
56
56
  request: {
57
57
  headers: request_headers,
58
58
  href: request.url,
59
- body: parse_body(request.body)
59
+ query_string: request.query_string,
60
+ body: request_body(request.path, request.body)
60
61
  },
61
62
  response: {
62
63
  status: status,
@@ -77,16 +78,25 @@ module PierLogging
77
78
  headers = env.select { |k,v| k[0..4] == 'HTTP_'}.
78
79
  transform_keys { |k| k[5..-1].split('_').join('-').upcase }
79
80
 
80
- return redact_hash(headers, hide_request_headers, nil) if hide_request_headers.present?
81
+ return redact_object(headers, hide_request_headers, nil) if hide_request_headers.present?
81
82
 
82
83
  headers
83
84
  end
84
85
 
86
+ def request_body(request_path, body)
87
+ return nil unless PierLogging.request_logger_configuration.log_request_body
88
+
89
+ hide_request_body_for_paths = PierLogging.request_logger_configuration.hide_request_body_for_paths
90
+ return nil if hide_request_body_for_paths&.any?{ |path|request_path =~ path }
91
+
92
+ parse_body(body)
93
+ end
94
+
85
95
  def response_body(request_path, body)
86
96
  return nil unless PierLogging.request_logger_configuration.log_response
87
97
 
88
98
  hide_response_body_for_paths = PierLogging.request_logger_configuration.hide_response_body_for_paths
89
- return nil if hide_response_body_for_paths && hide_response_body_for_paths.any?{ |path|request_path =~ path }
99
+ return nil if hide_response_body_for_paths&.any?{ |path|request_path =~ path }
90
100
 
91
101
  parse_body(body)
92
102
  end
@@ -119,13 +129,35 @@ module PierLogging
119
129
  body
120
130
  end
121
131
 
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
+
122
149
  def redact_hash(hash, replace_keys = REDACT_REPLACE_KEYS, replace_by = REDACT_REPLACE_BY)
123
- hash.traverse do |k,v|
150
+ raise StandardError, 'Could not redact_hash for non-hash objects' unless hash.is_a? Hash
151
+ hash.traverse do |k,v|
124
152
  should_redact = replace_keys.any?{ |regex| k =~regex }
125
153
  if (should_redact)
126
154
  [k, replace_by]
127
155
  else
128
- [k, v]
156
+ case v
157
+ when Array then [k, redact_array(v, replace_keys, replace_by)]
158
+ else
159
+ [k, v]
160
+ end
129
161
  end
130
162
  end
131
163
  end
@@ -1,3 +1,3 @@
1
1
  module PierLogging
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pier_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Banduk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai