kiev 4.7.0 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -3
- data/gemfiles/que_0.12.3.gemfile +1 -1
- data/gemfiles/sidekiq_4.2.gemfile +3 -0
- data/lib/kiev/base.rb +27 -14
- data/lib/kiev/config.rb +38 -3
- data/lib/kiev/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80613e919661165f768bd2a96b293c1908447e2cf936d7bf0f3b47e2338dec26
|
4
|
+
data.tar.gz: a49dffa5584e4a326ca21b10cdb6a82f091caf23a49d18241db3225343193ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb0cc47d3f960a1e761ed9e6647a9f3048ef6a4ed85ddd46c4c21c1f78d4dd2975f3842172570fba2570f968a23107d1d28133c5cc0a82c171fcc8892fa16f3
|
7
|
+
data.tar.gz: c54860b71c585ef469c9f425601e55d282cedaafde4860bcf0f46474bab9b5b7fe4f6cef460729c11de7af61636c9b099f6c7865f5ac336d8b6d3301a2444d69
|
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
|
+
### enable_filter_for_log_levels
|
458
|
+
You can specify for which log levels personal identifying information filter will be applied.
|
459
|
+
|
460
|
+
```ruby
|
461
|
+
Kiev.configure do |config|
|
462
|
+
# [DEBUG, INFO, WARN, ERROR, FATAL]
|
463
|
+
config.enable_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:
|
data/gemfiles/que_0.12.3.gemfile
CHANGED
@@ -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
|
+
:enable_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
|
26
|
-
Config.instance
|
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
|
34
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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 enable_filter_for_log_levels.include?(log_level)
|
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
|
+
:enable_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 =
|
120
|
+
@log_level = default_log_level
|
109
121
|
@persistent_log_fields = []
|
110
122
|
@pre_rack_hook = DEFAULT_PRE_RACK_HOOK
|
123
|
+
@enable_filter_for_log_levels = supported_log_levels.values
|
111
124
|
self.propagated_fields = {}
|
112
125
|
update_logger_settings
|
113
126
|
end
|
@@ -138,20 +151,32 @@ 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 enable_filter_for_log_levels=(log_levels)
|
161
|
+
raise ArgumentError, "Unsupported log levels" unless array_with_log_levels?(log_levels)
|
162
|
+
|
163
|
+
@enable_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
|
+
|
150
175
|
private
|
151
176
|
|
152
177
|
def update_logger_settings
|
153
178
|
@logger.formatter = formatter
|
154
|
-
@logger.level = @log_level
|
179
|
+
@logger.level = @log_level
|
155
180
|
end
|
156
181
|
|
157
182
|
def formatter
|
@@ -161,5 +186,15 @@ module Kiev
|
|
161
186
|
def default_log_level
|
162
187
|
development_mode ? ::Logger::DEBUG : ::Logger::INFO
|
163
188
|
end
|
189
|
+
|
190
|
+
def array_with_log_levels?(log_levels)
|
191
|
+
return false unless log_levels.is_a?(Array)
|
192
|
+
|
193
|
+
log_levels.all? { |level| supported_log_level?(level) }
|
194
|
+
end
|
195
|
+
|
196
|
+
def supported_log_level?(log_level)
|
197
|
+
supported_log_levels.value?(log_level)
|
198
|
+
end
|
164
199
|
end
|
165
200
|
end
|
data/lib/kiev/version.rb
CHANGED
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.
|
4
|
+
version: 4.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blacklane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-16 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
|
-
|
226
|
-
rubygems_version: 2.7.6
|
225
|
+
rubygems_version: 3.3.6
|
227
226
|
signing_key:
|
228
227
|
specification_version: 4
|
229
228
|
summary: Distributed logging to JSON integrated with various Ruby frameworks and tools
|