contextual_logger 1.2.0 → 1.3.0.dg.pre.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/contextual_logger/version.rb +1 -1
- data/lib/contextual_logger.rb +33 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96fa2fd042325883674d751a6b2443c23e9e6b195f9f15ade2826832c6557735
|
4
|
+
data.tar.gz: 180923158cdaac1c7cd63755ca93e4cda42aaf48bab442b21981264a255a5765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66081a0a05dded370cf77b2e60b2c20884e8993a362bf6be4674b3c4b0c95d4811c208b8b6ab64ea99495fc7ca05b16ba9ef779cb39f4169620a06eac0c12fce
|
7
|
+
data.tar.gz: 04d1997d713eec2231a08e2085728db8ef438268835b4ac6e3eb866ec01c7d5df0447677de127c286236aa0485d4e233b36214234aa661cd0c30c6fe52eaaef8
|
data/lib/contextual_logger.rb
CHANGED
@@ -19,6 +19,9 @@ module ContextualLogger
|
|
19
19
|
unknown: Logger::Severity::UNKNOWN
|
20
20
|
}.freeze
|
21
21
|
|
22
|
+
class LambdaAlreadyDefinedError < StandardError
|
23
|
+
end
|
24
|
+
|
22
25
|
class << self
|
23
26
|
def new(logger)
|
24
27
|
logger.extend(LoggerMixin)
|
@@ -57,6 +60,26 @@ module ContextualLogger
|
|
57
60
|
@global_context ||= Context::EMPTY_CONTEXT
|
58
61
|
end
|
59
62
|
|
63
|
+
def add_global_context_lambda(field, lambda)
|
64
|
+
if field.blank?
|
65
|
+
raise ArgumentError, "The field cannot be empty"
|
66
|
+
end
|
67
|
+
|
68
|
+
unless lambda.respond_to?(:call)
|
69
|
+
raise ArgumentError, "A lambda must respond to the :call method"
|
70
|
+
end
|
71
|
+
|
72
|
+
if global_context_lambdas[field]
|
73
|
+
raise ::ContextualLogger::LambdaAlreadyDefinedError, "A lambda for `#{field}` is already defined"
|
74
|
+
end
|
75
|
+
|
76
|
+
@global_context_lambdas[field] = lambda
|
77
|
+
end
|
78
|
+
|
79
|
+
def global_context_lambdas
|
80
|
+
@global_context_lambdas ||= {}
|
81
|
+
end
|
82
|
+
|
60
83
|
def global_context=(context)
|
61
84
|
if (global_context_lock_message = ::ContextualLogger.global_context_lock_message)
|
62
85
|
raise ::ContextualLogger::GlobalContextIsLocked, global_context_lock_message
|
@@ -136,7 +159,8 @@ module ContextualLogger
|
|
136
159
|
message = arg1
|
137
160
|
progname = arg2 || @progname
|
138
161
|
end
|
139
|
-
|
162
|
+
full_context = evaluate_global_context_lambdas(deep_merge_with_current_context(context))
|
163
|
+
write_entry_to_log(severity, Time.now, progname, message, context: full_context)
|
140
164
|
end
|
141
165
|
|
142
166
|
true
|
@@ -185,5 +209,13 @@ module ContextualLogger
|
|
185
209
|
current_context
|
186
210
|
end
|
187
211
|
end
|
212
|
+
|
213
|
+
def evaluate_global_context_lambdas(context)
|
214
|
+
if global_context_lambdas.empty?
|
215
|
+
context
|
216
|
+
else
|
217
|
+
global_context_lambdas.transform_values { |lambda| lambda.call }.merge(context)
|
218
|
+
end
|
219
|
+
end
|
188
220
|
end
|
189
221
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contextual_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0.dg.pre.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Ebentier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -69,9 +69,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: 1.3.1
|
75
75
|
requirements: []
|
76
76
|
rubygems_version: 3.1.6
|
77
77
|
signing_key:
|