kiev 4.7.0 → 4.8.2

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: 5da27510343d0217fedb4e4282cf9fc6468a63be4484935e2495e31205a2b188
4
- data.tar.gz: 3a7ac16381946c418fa4265ab440da10397514766e5c091a87847f4451644251
3
+ metadata.gz: b75d8c13ade0c1c19c620f32cd91f9ee8cfb181b88bbbb450bacc2740ed297de
4
+ data.tar.gz: 91dc05471b4dd9cd0b7d436b3c8e6df35760a11a269a48a64b575bf37bf02a3b
5
5
  SHA512:
6
- metadata.gz: ee5e47a70aae2576a0d119c0347fa9707f8a1ff53e8db3f5c1b8ae0bcc39907fd755f1d6112eca317e3b22ce8e2bdb59e83f3e9b70b86014fae995a4377da466
7
- data.tar.gz: d976cb714c3e9ca5a2f3aa9c0a505a78d38d4a1c77faddc408555dec2ff3f337dbc9430d881630165933084e2a5c88051ef6fbe530a2c79ebf2f24b64949a329
6
+ metadata.gz: 8e8928421ba2133504842a917a9a0188f81786eea86a7f88abc9b722bde7fad3e4d01d84610bd0b073678b06cad8f4735e1002ce05d3c473e68c7e7edc029a77
7
+ data.tar.gz: 20bf31e576d12ffea2a8a9b6c9bebfc9e27e00d0ef7bf0a2e446546bb622fa4b2e60a0666d51c64ba4d8ae20b3fb01bdab88fbec9e5f7d5f0957f69e7790cfe0
data/README.md CHANGED
@@ -176,13 +176,13 @@ Kiev::Kafka.inject_context(headers)
176
176
 
177
177
  After this operation the headers variable will also include required context for the Kiev logger.
178
178
 
179
- If you have a consumed `Kafka::FetchedMessage` you can extract logger context with:
179
+ If you have a consumed `Kafka::FetchedMessage` you can extract logger context with:
180
180
 
181
181
  ```ruby
182
182
  Kiev::Kafka.extract_context(message)
183
183
  ```
184
184
 
185
- This will work regardless if headers are in HTTP format, e.g. `X-Tracking-Id` or plain field names: `tracking_id`. Plus the `message_key` field will contain the key of processed message. In case you want to log some more fields configure `persistent_log_fields` and `jobs_propagated_fields`.
185
+ This will work regardless if headers are in HTTP format, e.g. `X-Tracking-Id` or plain field names: `tracking_id`. Plus the `message_key` field will contain the key of processed message. In case you want to log some more fields configure `persistent_log_fields` and `jobs_propagated_fields`.
186
186
 
187
187
  ### Que
188
188
 
@@ -251,7 +251,7 @@ For web requests the Kiev middleware will log the following information by defau
251
251
 
252
252
  * `request_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4). (currently deprecated in favor of a new name: `tracking_id`)
253
253
 
254
- * `tracking_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4). If not provided the value is seeded from deprecated `request_id`.
254
+ * `tracking_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4). If not provided the value is seeded from deprecated `request_id`.
255
255
 
256
256
  * `request_depth` represents the position of the current request within a chain of requests. It starts with 0.
257
257
 
@@ -317,6 +317,11 @@ Kiev.event(:my_event, { some_array: [1, 2, 3] })
317
317
 
318
318
  # Log other data types (will be available under the `message` key)
319
319
  Kiev.event(:my_event, "hello world")
320
+
321
+ # Log with given severity [debug, info, warn, error, fatal]
322
+ Kiev.info(:my_event)
323
+ Kiev.info(:my_event, { some_array: [1, 2, 3] })
324
+ Kiev.info(:my_event, "hello world")
320
325
  ```
321
326
 
322
327
  However, `Kiev.logger` implements the Ruby `Logger` class, so all the other methods are available as well:
@@ -439,6 +444,28 @@ get "/" do
439
444
  end
440
445
  ```
441
446
 
447
+ ### log_level
448
+ You can specify log level.
449
+
450
+ ```ruby
451
+ Kiev.configure do |config|
452
+ # One of: 0, 1, 2, 3, 4 (DEBUG, INFO, WARN, ERROR, FATAL)
453
+ config.log_level = 0
454
+ end
455
+ ```
456
+
457
+ ### disable_filter_for_log_levels
458
+ You can specify for which log levels personal identifying information filter will NOT be applied.
459
+
460
+ ```ruby
461
+ Kiev.configure do |config|
462
+ # [DEBUG, INFO, WARN, ERROR, FATAL]
463
+ config.disable_filter_for_log_levels = [0, 1, 2, 3, 4]
464
+ end
465
+ ```
466
+
467
+ **By default enabled for all suppported log levels.**
468
+
442
469
  ## nginx
443
470
 
444
471
  If you want to log 499 and 50x errors in nginx, which will not be captured by Ruby application, consider adding this to your nginx configuration:
@@ -6,7 +6,7 @@ source "https://rubygems.org"
6
6
  gem "multi_json"
7
7
  gem "oj"
8
8
 
9
- gem "que", ">= 0.12.3"
9
+ gem "que", "0.12.3"
10
10
  gem "pg"
11
11
  gem "sequel"
12
12
 
@@ -11,5 +11,8 @@ gem "rspec", require: false
11
11
  gem "minitest-reporters", require: false
12
12
 
13
13
  gem "her"
14
+ # We need to do it, since her gem doesn't lock upper boundry
15
+ # https://github.com/remi/her/blob/master/her.gemspec#L26
16
+ gem "faraday", "~> 1.9.3"
14
17
 
15
18
  gemspec path: "../"
data/lib/kiev/base.rb CHANGED
@@ -13,33 +13,38 @@ require_relative "config"
13
13
  require_relative "util"
14
14
  require_relative "subrequest_helper"
15
15
  require_relative "hanami"
16
+ require "forwardable"
17
+ require "logger"
16
18
 
17
19
  module Kiev
18
20
  class << self
21
+ extend Forwardable
22
+
23
+ def_delegators :config,
24
+ :logger,
25
+ :filtered_params,
26
+ :ignored_params,
27
+ :log_level,
28
+ :disable_filter_for_log_levels
29
+
19
30
  EMPTY_OBJ = {}.freeze
20
31
 
21
32
  def configure
22
33
  yield(Config.instance)
23
34
  end
24
35
 
25
- def logger
26
- Config.instance.logger
27
- end
28
-
29
- def filtered_params
30
- Config.instance.filtered_params
36
+ def config
37
+ Config.instance
31
38
  end
32
39
 
33
- def ignored_params
34
- Config.instance.ignored_params
40
+ def event(log_name, data = EMPTY_OBJ, severity = log_level)
41
+ logger.log(severity, logged_data(data), log_name)
35
42
  end
36
43
 
37
- def event(log_name, data = EMPTY_OBJ)
38
- logger.log(
39
- ::Logger::Severity::INFO,
40
- ParamFilter.filter(data, filtered_params, ignored_params),
41
- log_name
42
- )
44
+ Config.instance.supported_log_levels.each_pair do |key, value|
45
+ define_method(key) do |log_name, data = EMPTY_OBJ|
46
+ event(log_name, data, value)
47
+ end
43
48
  end
44
49
 
45
50
  def []=(name, value)
@@ -63,5 +68,13 @@ module Kiev
63
68
  end
64
69
 
65
70
  alias_method :tracking_id, :request_id
71
+
72
+ private
73
+
74
+ def logged_data(data)
75
+ return data unless config.filter_enabled?
76
+
77
+ ParamFilter.filter(data, filtered_params, ignored_params)
78
+ end
66
79
  end
67
80
  end
data/lib/kiev/config.rb CHANGED
@@ -75,6 +75,16 @@ module Kiev
75
75
  end
76
76
  end
77
77
 
78
+ SUPPORTED_LOG_LEVELS = {
79
+ debug: ::Logger::DEBUG,
80
+ info: ::Logger::INFO,
81
+ warn: ::Logger::WARN,
82
+ error: ::Logger::ERROR,
83
+ fatal: ::Logger::FATAL
84
+ }.freeze
85
+
86
+ private_constant :SUPPORTED_LOG_LEVELS
87
+
78
88
  attr_accessor :app,
79
89
  :log_request_condition,
80
90
  :log_request_error_condition,
@@ -89,10 +99,12 @@ module Kiev
89
99
 
90
100
  attr_reader :development_mode,
91
101
  :logger,
102
+ :log_level,
92
103
  :http_propagated_fields,
93
104
  :jobs_propagated_fields,
94
105
  :all_http_propagated_fields, # for internal use
95
- :all_jobs_propagated_fields # for internal use
106
+ :all_jobs_propagated_fields, # for internal use
107
+ :disable_filter_for_log_levels
96
108
 
97
109
  def initialize
98
110
  @log_request_condition = DEFAULT_LOG_REQUEST_CONDITION
@@ -105,9 +117,10 @@ module Kiev
105
117
  @development_mode = false
106
118
  @ignored_rack_exceptions = DEFAULT_IGNORED_RACK_EXCEPTIONS.dup
107
119
  @logger = Kiev::Logger.new(STDOUT)
108
- @log_level = nil
120
+ @log_level = default_log_level
109
121
  @persistent_log_fields = []
110
122
  @pre_rack_hook = DEFAULT_PRE_RACK_HOOK
123
+ @disable_filter_for_log_levels = []
111
124
  self.propagated_fields = {}
112
125
  update_logger_settings
113
126
  end
@@ -138,20 +151,36 @@ module Kiev
138
151
  end
139
152
 
140
153
  def log_level=(value)
154
+ raise ArgumentError, "Unsupported log level #{value}" unless supported_log_level?(value)
155
+
141
156
  @log_level = value
142
157
  update_logger_settings
143
158
  end
144
159
 
160
+ def disable_filter_for_log_levels=(log_levels)
161
+ raise ArgumentError, "Unsupported log levels" unless array_with_log_levels?(log_levels)
162
+
163
+ @disable_filter_for_log_levels = log_levels
164
+ end
165
+
145
166
  def development_mode=(value)
146
167
  @development_mode = value
147
168
  update_logger_settings
148
169
  end
149
170
 
171
+ def supported_log_levels
172
+ SUPPORTED_LOG_LEVELS
173
+ end
174
+
175
+ def filter_enabled?
176
+ !disable_filter_for_log_levels.include?(log_level)
177
+ end
178
+
150
179
  private
151
180
 
152
181
  def update_logger_settings
153
182
  @logger.formatter = formatter
154
- @logger.level = @log_level || default_log_level
183
+ @logger.level = @log_level
155
184
  end
156
185
 
157
186
  def formatter
@@ -161,5 +190,15 @@ module Kiev
161
190
  def default_log_level
162
191
  development_mode ? ::Logger::DEBUG : ::Logger::INFO
163
192
  end
193
+
194
+ def array_with_log_levels?(log_levels)
195
+ return false unless log_levels.is_a?(Array)
196
+
197
+ log_levels.all? { |level| supported_log_level?(level) }
198
+ end
199
+
200
+ def supported_log_level?(log_level)
201
+ supported_log_levels.value?(log_level)
202
+ end
164
203
  end
165
204
  end
@@ -29,6 +29,9 @@ module Kiev
29
29
  def self.filter(content_type, request_body, filtered_params, ignored_params)
30
30
  body = request_body.read
31
31
  request_body.rewind
32
+
33
+ return body unless Kiev.config.filter_enabled?
34
+
32
35
  body_filter = for_content_type(content_type)
33
36
  body_filter.call(body, filtered_params, ignored_params)
34
37
  end
data/lib/kiev/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kiev
4
- VERSION = "4.7.0"
4
+ VERSION = "4.8.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiev
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blacklane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga
@@ -222,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubyforge_project:
226
- rubygems_version: 2.7.6
225
+ rubygems_version: 3.3.7
227
226
  signing_key:
228
227
  specification_version: 4
229
228
  summary: Distributed logging to JSON integrated with various Ruby frameworks and tools