getaround_utils 0.1.11 → 0.1.12
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/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/lib/getaround_utils/log_formatters/deep_key_value.rb +28 -18
- data/lib/getaround_utils/mixins/loggable.rb +1 -5
- data/lib/getaround_utils/patches/key_value_log_tags.rb +12 -8
- data/lib/getaround_utils/patches/key_value_sidekiq_exceptions.rb +2 -6
- data/lib/getaround_utils/utils/{deep_key_value_serializer.rb → deep_key_value.rb} +9 -14
- data/lib/getaround_utils/utils.rb +1 -1
- data/lib/getaround_utils/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8111d0bfe63899265268fea8edcea433312a1286299d5b00f67fd5eb658c813
|
4
|
+
data.tar.gz: bb7c45164af9db998c5f0008f4dbec5288ff87f49d923f28916c79af94683bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f0992f71d843c927bd5d6dffe170980c3a7adfc6dce0997b49c6299159593ba9866f7d68b70a0feeaf59689913f7a5f9fc22cddab0c11a59d78800c19fd1d16
|
7
|
+
data.tar.gz: e8c73735d0189471f259da0c57a9821bf98c741718877558d1918c1a2500fc3b910ca2d7c6a0cc4d71516e8099d506ffdad10eaae2496af64a5bd6fd4218b065
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5
|
data/Gemfile.lock
CHANGED
@@ -1,36 +1,46 @@
|
|
1
1
|
module GetaroundUtils; end
|
2
2
|
module GetaroundUtils::LogFormatters; end
|
3
3
|
|
4
|
-
require 'getaround_utils/utils/
|
5
|
-
|
6
|
-
class GetaroundUtils::LogFormatters::DeepKeyValue
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
message
|
12
|
-
|
13
|
-
|
4
|
+
require 'getaround_utils/utils/deep_key_value'
|
5
|
+
|
6
|
+
class GetaroundUtils::LogFormatters::DeepKeyValue
|
7
|
+
module Shared
|
8
|
+
def normalize(message)
|
9
|
+
if message.is_a?(Hash)
|
10
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(message.compact)
|
11
|
+
elsif message.is_a?(String) && message.match(/^[^ =]+=/)
|
12
|
+
message
|
13
|
+
else
|
14
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(message: message.to_s)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
class Base
|
20
|
+
include GetaroundUtils::LogFormatters::DeepKeyValue::Shared
|
21
|
+
|
22
|
+
def call(severity, _datetime, appname, message)
|
23
|
+
payload = { severity: severity, appname: appname }
|
24
|
+
"#{normalize(payload)} #{normalize(message)}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.new
|
29
|
+
Base.new
|
20
30
|
end
|
21
31
|
|
22
|
-
|
32
|
+
class Lograge
|
23
33
|
def call(message)
|
24
34
|
message = message.compact if message.is_a?(Hash)
|
25
|
-
serialize(message)
|
35
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(message)
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
39
|
def self.for_lograge
|
30
|
-
new
|
40
|
+
Lograge.new
|
31
41
|
end
|
32
42
|
|
33
|
-
|
43
|
+
class Sidekiq < Base
|
34
44
|
def sidekiq_context
|
35
45
|
context = Thread.current&.fetch(:sidekiq_context, nil)
|
36
46
|
context.is_a?(Hash) ? context : {}
|
@@ -48,6 +58,6 @@ class GetaroundUtils::LogFormatters::DeepKeyValue < GetaroundUtils::Utils::DeepK
|
|
48
58
|
end
|
49
59
|
|
50
60
|
def self.for_sidekiq
|
51
|
-
new
|
61
|
+
Sidekiq.new
|
52
62
|
end
|
53
63
|
end
|
@@ -24,15 +24,11 @@ module GetaroundUtils::Mixins::Loggable
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def loggable_formatter
|
28
|
-
@loggable_formatter ||= GetaroundUtils::Utils::DeepKeyValueSerializer.new
|
29
|
-
end
|
30
|
-
|
31
27
|
def loggable(severity, message, payload = {})
|
32
28
|
payload = { message: message }.merge(payload)
|
33
29
|
base_append_infos_to_loggable(payload)
|
34
30
|
|
35
|
-
message =
|
31
|
+
message = GetaroundUtils::Utils::DeepKeyValue.serialize(payload.compact)
|
36
32
|
base_loggable_logger.send(severity.to_sym, message)
|
37
33
|
end
|
38
34
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'getaround_utils/
|
1
|
+
require 'getaround_utils/log_formatters/deep_key_value'
|
2
2
|
|
3
3
|
module GetaroundUtils; end
|
4
4
|
module GetaroundUtils::Patches; end
|
@@ -18,25 +18,29 @@ module GetaroundUtils::Patches; end
|
|
18
18
|
|
19
19
|
class GetaroundUtils::Patches::KeyValueLogTags
|
20
20
|
module TaggedLoggingFormatter
|
21
|
+
include GetaroundUtils::LogFormatters::DeepKeyValue::Shared
|
22
|
+
|
21
23
|
def tags_text
|
22
24
|
"#{current_tags.join(' ')} " if current_tags.any?
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def call(severity, datetime, appname, message)
|
28
|
+
original_method = method(__method__).super_method.super_method
|
29
|
+
message = "#{tags_text}#{normalize(message)}"
|
30
|
+
original_method.call(severity, datetime, appname, message)
|
29
31
|
end
|
32
|
+
end
|
30
33
|
|
34
|
+
module RackLogger
|
31
35
|
def compute_tags(request)
|
32
36
|
@taggers.collect do |tag|
|
33
37
|
case tag
|
34
38
|
when Proc
|
35
|
-
|
39
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(tag.call(request))
|
36
40
|
when Symbol
|
37
|
-
|
41
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(tag => request.send(tag))
|
38
42
|
else
|
39
|
-
|
43
|
+
GetaroundUtils::Utils::DeepKeyValue.serialize(tag)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
@@ -1,22 +1,18 @@
|
|
1
1
|
require 'sidekiq/exception_handler'
|
2
|
-
require 'getaround_utils/utils/
|
2
|
+
require 'getaround_utils/utils/deep_key_value'
|
3
3
|
|
4
4
|
module GetaroundUtils; end
|
5
5
|
module GetaroundUtils::Patches; end
|
6
6
|
|
7
7
|
class GetaroundUtils::Patches::KeyValueSidekiqExceptions
|
8
8
|
module ExceptionHandlerLogger
|
9
|
-
def kv_formatter
|
10
|
-
@kv_formatter ||= GetaroundUtils::Utils::DeepKeyValueSerializer.new
|
11
|
-
end
|
12
|
-
|
13
9
|
def call(exception, ctx)
|
14
10
|
payload = {}
|
15
11
|
payload[:message] = exception.message
|
16
12
|
payload[:exception] = exception.class.name
|
17
13
|
payload[:backtrace] = exception.backtrace&.join("\n")
|
18
14
|
payload[:sidekiq] = ctx
|
19
|
-
Sidekiq.logger.warn(
|
15
|
+
Sidekiq.logger.warn(GetaroundUtils::Utils::DeepKeyValue.serialize(payload.compact))
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
@@ -1,13 +1,8 @@
|
|
1
1
|
module GetaroundUtils; end
|
2
2
|
module GetaroundUtils::Utils; end
|
3
3
|
|
4
|
-
|
5
|
-
def
|
6
|
-
@max_depth = max_depth
|
7
|
-
@max_length = max_length
|
8
|
-
end
|
9
|
-
|
10
|
-
def serialize(data)
|
4
|
+
module GetaroundUtils::Utils::DeepKeyValue
|
5
|
+
def self.serialize(data)
|
11
6
|
case data
|
12
7
|
when Array
|
13
8
|
flattify(data).map { |key, value| "#{key}=#{value}" }.join(' ')
|
@@ -23,31 +18,31 @@ class GetaroundUtils::Utils::DeepKeyValueSerializer
|
|
23
18
|
end
|
24
19
|
|
25
20
|
# https://stackoverflow.com/questions/48836464/how-to-flatten-a-hash-making-each-key-a-unique-value
|
26
|
-
def flattify(value, result = {}, path = [])
|
27
|
-
if path.length >
|
21
|
+
def self.flattify(value, result = {}, path = [], max_length = 512, max_depth = 5)
|
22
|
+
if path.length > max_depth
|
28
23
|
result[path.join(".")] = '"..."'
|
29
24
|
return result
|
30
25
|
end
|
31
26
|
case value
|
32
27
|
when Array
|
33
28
|
value.each.with_index(0) do |v, i|
|
34
|
-
flattify(v, result, path + [i])
|
29
|
+
flattify(v, result, path + [i], max_length, max_depth)
|
35
30
|
end
|
36
31
|
when Hash
|
37
32
|
value.each do |k, v|
|
38
|
-
flattify(v, result, path + [k])
|
33
|
+
flattify(v, result, path + [k], max_length, max_depth)
|
39
34
|
end
|
40
35
|
when Numeric
|
41
36
|
result[path.join(".")] = value.to_s
|
42
37
|
when String
|
43
38
|
value = if value =~ /^".*"$/
|
44
|
-
value.length >=
|
39
|
+
value.length >= max_length ? %{#{value[0...max_length]} ..."} : value
|
45
40
|
else
|
46
|
-
value.length >=
|
41
|
+
value.length >= max_length ? %{#{value[0...max_length]} ...}.inspect : value.inspect
|
47
42
|
end
|
48
43
|
result[path.join(".")] = value
|
49
44
|
else
|
50
|
-
flattify(value.to_s, result, path)
|
45
|
+
flattify(value.to_s, result, path, max_length, max_depth)
|
51
46
|
end
|
52
47
|
result
|
53
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getaround_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drivy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-11-
|
12
|
+
date: 2019-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -197,6 +197,7 @@ extensions: []
|
|
197
197
|
extra_rdoc_files: []
|
198
198
|
files:
|
199
199
|
- ".rubocop.yml"
|
200
|
+
- ".ruby-version"
|
200
201
|
- Gemfile
|
201
202
|
- Gemfile.lock
|
202
203
|
- README.md
|
@@ -211,7 +212,7 @@ files:
|
|
211
212
|
- lib/getaround_utils/patches/key_value_sidekiq_exceptions.rb
|
212
213
|
- lib/getaround_utils/railties/lograge.rb
|
213
214
|
- lib/getaround_utils/utils.rb
|
214
|
-
- lib/getaround_utils/utils/
|
215
|
+
- lib/getaround_utils/utils/deep_key_value.rb
|
215
216
|
- lib/getaround_utils/version.rb
|
216
217
|
homepage: https://github.com/drivy
|
217
218
|
licenses:
|