on_strum-logs 0.2.0 → 1.0.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ecbe6a25ee37ba18625810f3c21d555a0b5ae11a35883167438e4368576311e
|
4
|
+
data.tar.gz: d6604a0734775516a73bcc5a5ffbe63f9741cf86f40f69e5e2a6d3a3b47aba3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '01390b62cd01dd39b8f49d0cf3d60a5e557cc37b6ef3543274f49173d25e1bb4666a04d3c89bd018f1d65a727e7c394fe8326642b763843c9b9adcc753c59114'
|
7
|
+
data.tar.gz: 645e4a74b4130d79400a49d7b75d73fcebccbff71a7d80b7a45545e364a411836554c747949f5b6ecb52b34ce2c7380b08872694ad1b8e3fbf99e4aeb3323322
|
@@ -3,13 +3,23 @@
|
|
3
3
|
module OnStrum
|
4
4
|
module Logs
|
5
5
|
class Configuration
|
6
|
-
|
7
|
-
|
6
|
+
SETTERS = %i[
|
7
|
+
custom_formatter
|
8
|
+
root_fields
|
9
|
+
field_name_level
|
10
|
+
field_name_time
|
11
|
+
field_name_message
|
12
|
+
field_name_context
|
13
|
+
field_name_exception_message
|
14
|
+
field_name_exception_stack_trace
|
15
|
+
].freeze
|
16
|
+
BUILTIN_FIELDS_DEFAULT_NAMES = %i[level time message context stack_trace].freeze
|
8
17
|
|
9
18
|
attr_reader(*OnStrum::Logs::Configuration::SETTERS)
|
10
19
|
attr_accessor :detailed_formatter
|
11
20
|
|
12
21
|
def initialize(&block)
|
22
|
+
instance_initializer.each { |instace_variable, value| instance_variable_set(:"@#{instace_variable}", value) }
|
13
23
|
tap(&block) if block
|
14
24
|
end
|
15
25
|
|
@@ -20,21 +30,37 @@ module OnStrum
|
|
20
30
|
end
|
21
31
|
end
|
22
32
|
|
23
|
-
def complete?
|
24
|
-
!!(service_name && service_version)
|
25
|
-
end
|
26
|
-
|
27
33
|
def formatter
|
28
34
|
custom_formatter || builded_formatter
|
29
35
|
end
|
30
36
|
|
37
|
+
def log_attributes_order
|
38
|
+
@log_attributes_order ||= OnStrum::Logs::Configuration::SETTERS[2..5].map do |field_name_getter|
|
39
|
+
public_send(field_name_getter)
|
40
|
+
end + root_fields.keys
|
41
|
+
end
|
42
|
+
|
31
43
|
private
|
32
44
|
|
45
|
+
def instance_initializer
|
46
|
+
message_key = OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[2]
|
47
|
+
{
|
48
|
+
root_fields: {},
|
49
|
+
field_name_level: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[0],
|
50
|
+
field_name_time: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[1],
|
51
|
+
field_name_message: message_key,
|
52
|
+
field_name_context: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[3],
|
53
|
+
field_name_exception_message: message_key,
|
54
|
+
field_name_exception_stack_trace: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[4]
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
33
58
|
def valid_argument_type?(method_name, argument)
|
34
59
|
argument.is_a?(
|
35
60
|
case method_name
|
36
|
-
when
|
61
|
+
when *OnStrum::Logs::Configuration::SETTERS[2..-1] then ::Symbol
|
37
62
|
when :custom_formatter then ::Class
|
63
|
+
when :root_fields then ::Hash
|
38
64
|
end
|
39
65
|
)
|
40
66
|
end
|
@@ -5,10 +5,9 @@ module OnStrum
|
|
5
5
|
module Formatter
|
6
6
|
class Base
|
7
7
|
DATETIME_FORMAT = '%FT%T.%3N%:z'
|
8
|
-
LOG_ATTRIBUTES_ORDER = %i[level time message context service_name service_version].freeze
|
9
8
|
|
10
9
|
def self.arrange_attrs(**log_data)
|
11
|
-
OnStrum::Logs
|
10
|
+
OnStrum::Logs.configuration.log_attributes_order.each_with_object({}) do |attribute, arranged_attrs|
|
12
11
|
arranged_attrs[attribute] = log_data[attribute]
|
13
12
|
end
|
14
13
|
end
|
@@ -6,10 +6,11 @@ module OnStrum
|
|
6
6
|
class Json < Base
|
7
7
|
require 'json'
|
8
8
|
|
9
|
-
def self.call(
|
9
|
+
def self.call(**log_data)
|
10
|
+
time_key = OnStrum::Logs.configuration.field_name_time
|
10
11
|
json_log = arrange_attrs(
|
11
|
-
|
12
|
-
|
12
|
+
**log_data,
|
13
|
+
time_key => log_data[time_key].strftime(OnStrum::Logs::Formatter::Base::DATETIME_FORMAT)
|
13
14
|
).to_json
|
14
15
|
|
15
16
|
"#{json_log}\n"
|
@@ -20,7 +20,10 @@ module OnStrum
|
|
20
20
|
|
21
21
|
# TODO: we need to have ability to process log data before render it to STDOUT/STDERR
|
22
22
|
# hash_normalizer(arg); after_callback.call(arg)
|
23
|
-
logger.public_send(
|
23
|
+
logger.public_send(
|
24
|
+
method_name,
|
25
|
+
hash_normalizer(arg).merge(configuration.field_name_level => method_name.to_s.upcase)
|
26
|
+
)
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -35,29 +38,30 @@ module OnStrum
|
|
35
38
|
def formatter
|
36
39
|
@formatter ||= proc do |_severity, datetime, _progname, log_data|
|
37
40
|
configuration.formatter.call(
|
38
|
-
|
39
|
-
|
40
|
-
service_version: configuration.service_version,
|
41
|
+
configuration.field_name_time => datetime,
|
42
|
+
**configuration.root_fields,
|
41
43
|
**log_data
|
42
44
|
)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
48
|
def hash_normalizer(object)
|
49
|
+
message_key, context_key = configuration.field_name_message, configuration.field_name_context
|
50
|
+
|
47
51
|
case object
|
48
52
|
when ::Hash
|
49
|
-
raise OnStrum::Logs::Error::Logger unless object.key?(
|
53
|
+
raise OnStrum::Logs::Error::Logger unless object.key?(message_key)
|
50
54
|
|
51
|
-
{
|
55
|
+
{ message_key => object.delete(message_key), context_key => (object.empty? ? nil : object) }
|
52
56
|
when ::Exception
|
53
57
|
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
message_key => "Exception: #{object.class}",
|
59
|
+
context_key => {
|
60
|
+
configuration.field_name_exception_message => object.message,
|
61
|
+
configuration.field_name_exception_stack_trace => object.backtrace
|
58
62
|
}
|
59
63
|
}
|
60
|
-
else {
|
64
|
+
else { message_key => object.to_s, context_key => nil }
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
data/lib/on_strum/logs.rb
CHANGED
@@ -9,10 +9,7 @@ module OnStrum
|
|
9
9
|
@configuration ||= begin
|
10
10
|
return unless block
|
11
11
|
|
12
|
-
|
13
|
-
raise OnStrum::Logs::Error::Configuration, OnStrum::Logs::Configuration::INCOMPLETE_CONFIG unless configuration.complete?
|
14
|
-
|
15
|
-
configuration
|
12
|
+
OnStrum::Logs::Configuration.new(&block)
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: on_strum-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Trotsenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|