usps-imis-api 0.15.1 → 0.15.2
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/lib/usps/imis/config.rb +9 -0
- data/lib/usps/imis/logger.rb +17 -2
- data/lib/usps/imis/logger_helpers.rb +11 -0
- data/lib/usps/imis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71bf86bea5de43c3a42aee00194fc56a1e0b42269e960e49508f8f2b1cc3e22f
|
|
4
|
+
data.tar.gz: d5721fd614d0da0f92d24e495d9cc4de8631af9d1609c9a5cca9eee6fc24a31b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b414c11006fca75e300b1847474aab6319aaac3807eab7a025bb13d45c44d248a2b894b651affda14e7924341f6dea722bd2613d275cfeea908f9589cfa05535
|
|
7
|
+
data.tar.gz: b302e648c10ab09c427acfdc90fe9622b1fda6e03e6587ce8be1e7dc96c33b2c98cd293ea9191f6c78428193e55f395252cba5ee337e046a9716783264cfd24c
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -107,6 +107,14 @@ module Usps
|
|
|
107
107
|
@global_logger = build_global_logger
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
+
# Whether the global mirror debug logger writes anywhere. Disabled or unwritable, it is a null
|
|
111
|
+
# logger, and nothing needs to be mirrored to it.
|
|
112
|
+
#
|
|
113
|
+
def global_logging?
|
|
114
|
+
global_logger
|
|
115
|
+
@global_logging
|
|
116
|
+
end
|
|
117
|
+
|
|
110
118
|
def silence!
|
|
111
119
|
self.logger = Logger.new(nil)
|
|
112
120
|
end
|
|
@@ -153,6 +161,7 @@ module Usps
|
|
|
153
161
|
rescue StandardError
|
|
154
162
|
false
|
|
155
163
|
end
|
|
164
|
+
@global_logging = writable
|
|
156
165
|
return ActiveSupport::TaggedLogging.new(::Logger.new(nil)) unless writable
|
|
157
166
|
|
|
158
167
|
ActiveSupport::TaggedLogging.new(
|
data/lib/usps/imis/logger.rb
CHANGED
|
@@ -12,14 +12,29 @@ module Usps
|
|
|
12
12
|
self.formatter = LoggerFormatter.new
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
# Also send logger methods to the global logger
|
|
15
|
+
# Also send logger methods to the global logger, while it is writing anywhere
|
|
16
16
|
#
|
|
17
17
|
%w[debug info warn error fatal unknown].each do |method|
|
|
18
18
|
define_method(method) do |message|
|
|
19
19
|
super(message)
|
|
20
|
-
Usps::Imis.config.
|
|
20
|
+
mirror(method, message) if Usps::Imis.config.global_logging?
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
# Whether a message at this level is recorded anywhere: here, or by the global logger, which
|
|
25
|
+
# records everything while it is writing
|
|
26
|
+
#
|
|
27
|
+
def logs?(level) = super || Usps::Imis.config.global_logging?
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# The block form tags this one message, rather than building a tagged copy of the global logger
|
|
32
|
+
# for every line logged
|
|
33
|
+
#
|
|
34
|
+
def mirror(method, message)
|
|
35
|
+
global_logger = Usps::Imis.config.global_logger
|
|
36
|
+
global_logger.tagged(formatter.current_tags) { global_logger.public_send(method, message) }
|
|
37
|
+
end
|
|
23
38
|
end
|
|
24
39
|
end
|
|
25
40
|
end
|
|
@@ -5,11 +5,22 @@ module Usps
|
|
|
5
5
|
# Formatted logger helpers
|
|
6
6
|
#
|
|
7
7
|
module LoggerHelpers
|
|
8
|
+
# Whether a message at this level is recorded at all
|
|
9
|
+
#
|
|
10
|
+
def logs?(level) = public_send(:"#{level}?")
|
|
11
|
+
|
|
12
|
+
# Each line is logged on its own, so nothing is formatted or split for a level that would only
|
|
13
|
+
# discard them -- a full query page is tens of thousands of lines
|
|
14
|
+
#
|
|
8
15
|
def multiline(string, level: :debug)
|
|
16
|
+
return unless logs?(level)
|
|
17
|
+
|
|
9
18
|
string.split("\n").each { public_send(level, it) }
|
|
10
19
|
end
|
|
11
20
|
|
|
12
21
|
def json(data, level: :debug)
|
|
22
|
+
return unless logs?(level)
|
|
23
|
+
|
|
13
24
|
hash = data.is_a?(String) ? JSON.parse(data) : data
|
|
14
25
|
tagged('JSON') { multiline(JSON.pretty_generate(hash), level:) }
|
|
15
26
|
rescue StandardError
|
data/lib/usps/imis/version.rb
CHANGED