oslg 0.2.8 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oslg/oslog.rb +114 -78
- data/lib/oslg/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40136c79318618e246c6ff26888af0bc84e1bb487dacaa5dbc181a9e33e851c4
|
4
|
+
data.tar.gz: 37432f3791f7db1a2607c9d9bc166254d071df026cf8fc02609867c7ae5e9f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 640fd6603a0260afc01a80a6e037b1c01bc5a2a49b8b9b193ac71ddf120f71b7a69b78f26650a765d55a878e77116166903b5726c3ca7ef8ed38f524e5ec67a7
|
7
|
+
data.tar.gz: 73b1158d0fa33232801267293695d088ddac2ca13503a7d8b27db1e0624238a626ed4ec51b9b767b15780f24182622363daf3fcb25c94d760cd82dc89933e0a4
|
data/lib/oslg/oslog.rb
CHANGED
@@ -29,14 +29,35 @@
|
|
29
29
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
30
|
|
31
31
|
module OSlg
|
32
|
-
DEBUG
|
33
|
-
INFO
|
34
|
-
WARN
|
35
|
-
ERROR
|
36
|
-
FATAL
|
32
|
+
DEBUG = 1 # e.g. for debugging e.g. "argument String? expecting Integer"
|
33
|
+
INFO = 2 # e.g. informative e.g. "success! no errors, no warnings"
|
34
|
+
WARN = 3 # e.g. warnings e.g. "partial success, see non-fatal warnings"
|
35
|
+
ERROR = 4 # e.g. erros e.g. "partial success, see non-fatal errors"
|
36
|
+
FATAL = 5 # e.g. failures e.g. "stopping! encountered fatal errors"
|
37
37
|
|
38
38
|
# each log is a Hash with keys :level (Integer) and :message (String)
|
39
|
-
@@logs
|
39
|
+
@@logs = []
|
40
|
+
|
41
|
+
# preset strings matching log levels
|
42
|
+
@@tag = [
|
43
|
+
"", # (empty string)
|
44
|
+
"DEBUG", # DEBUG
|
45
|
+
"INFO", # INFO
|
46
|
+
"WARNING", # WARNING
|
47
|
+
"ERROR", # ERROR
|
48
|
+
"FATAL" # FATAL
|
49
|
+
].freeze
|
50
|
+
|
51
|
+
# preset strings matching log status
|
52
|
+
@@msg = [
|
53
|
+
"", # (empty string)
|
54
|
+
"Debugging ...", # DEBUG
|
55
|
+
"Success! No errors, no warnings", # INFO
|
56
|
+
"Partial success, raised non-fatal warnings", # WARNING
|
57
|
+
"Partial success, encountered non-fatal errors", # ERROR
|
58
|
+
"Failure, triggered fatal errors" # FATAL
|
59
|
+
].freeze
|
60
|
+
|
40
61
|
@@level = INFO # initial log level
|
41
62
|
@@status = 0 # initial status
|
42
63
|
|
@@ -51,7 +72,7 @@ module OSlg
|
|
51
72
|
##
|
52
73
|
# Returns current log level.
|
53
74
|
#
|
54
|
-
# @return [
|
75
|
+
# @return [DEBUG, INFO, WARN, ERROR, FATAL] log level
|
55
76
|
def level
|
56
77
|
@@level
|
57
78
|
end
|
@@ -59,7 +80,7 @@ module OSlg
|
|
59
80
|
##
|
60
81
|
# Returns current log status.
|
61
82
|
#
|
62
|
-
# @return [
|
83
|
+
# @return [0, DEBUG, INFO, WARN, ERROR, FATAL] log status
|
63
84
|
def status
|
64
85
|
@@status
|
65
86
|
end
|
@@ -67,7 +88,7 @@ module OSlg
|
|
67
88
|
##
|
68
89
|
# Returns whether current status is DEBUG.
|
69
90
|
#
|
70
|
-
# @return [Bool]
|
91
|
+
# @return [Bool] whether current log status is DEBUG
|
71
92
|
def debug?
|
72
93
|
@@status == DEBUG
|
73
94
|
end
|
@@ -75,7 +96,7 @@ module OSlg
|
|
75
96
|
##
|
76
97
|
# Returns whether current status is INFO.
|
77
98
|
#
|
78
|
-
# @return [Bool]
|
99
|
+
# @return [Bool] whether current log status is INFO
|
79
100
|
def info?
|
80
101
|
@@status == INFO
|
81
102
|
end
|
@@ -83,7 +104,7 @@ module OSlg
|
|
83
104
|
##
|
84
105
|
# Returns whether current status is WARN.
|
85
106
|
#
|
86
|
-
# @return [Bool]
|
107
|
+
# @return [Bool] whether current log status is WARN
|
87
108
|
def warn?
|
88
109
|
@@status == WARN
|
89
110
|
end
|
@@ -91,7 +112,7 @@ module OSlg
|
|
91
112
|
##
|
92
113
|
# Returns whether current status is ERROR.
|
93
114
|
#
|
94
|
-
# @return [Bool]
|
115
|
+
# @return [Bool] whether current log status is ERROR
|
95
116
|
def error?
|
96
117
|
@@status == ERROR
|
97
118
|
end
|
@@ -99,17 +120,68 @@ module OSlg
|
|
99
120
|
##
|
100
121
|
# Returns whether current status is FATAL.
|
101
122
|
#
|
102
|
-
# @return [Bool]
|
123
|
+
# @return [Bool] whether current log status is FATAL
|
103
124
|
def fatal?
|
104
125
|
@@status == FATAL
|
105
126
|
end
|
106
127
|
|
128
|
+
##
|
129
|
+
# Returns preset OSlg string that matches log level.
|
130
|
+
#
|
131
|
+
# @param lvl [#to_i] 0, DEBUG, INFO, WARN, ERROR or FATAL
|
132
|
+
#
|
133
|
+
# @return [String] preset OSlg tag (see @@tag)
|
134
|
+
def tag(lvl)
|
135
|
+
return "" unless lvl.respond_to?(:to_i)
|
136
|
+
|
137
|
+
lvl = lvl.to_i
|
138
|
+
return "" if lvl < DEBUG
|
139
|
+
return "" if lvl > FATAL
|
140
|
+
|
141
|
+
@@tag[lvl]
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Returns preset OSlg message that matches log status.
|
147
|
+
#
|
148
|
+
# @param stat [Integer] 0, DEBUG, INFO, WARN, ERROR or FATAL
|
149
|
+
#
|
150
|
+
# @return [String] preset OSlg message (see @@msg)
|
151
|
+
def msg(stat)
|
152
|
+
return "" unless stat.respond_to?(:to_i)
|
153
|
+
|
154
|
+
stat = stat.to_i
|
155
|
+
return "" if stat < DEBUG
|
156
|
+
return "" if stat > FATAL
|
157
|
+
|
158
|
+
@@msg[stat]
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Converts object to String and trims if necessary.
|
163
|
+
#
|
164
|
+
# @param txt [#to_s] a stringable object
|
165
|
+
# @param length [#to_i] maximum return string length
|
166
|
+
#
|
167
|
+
# @return [String] a trimmed message string (empty unless stringable)
|
168
|
+
def trim(txt = "", length = 60)
|
169
|
+
length = 60 unless length.respond_to?(:to_i)
|
170
|
+
length = length.to_i if length.respond_to?(:to_i)
|
171
|
+
return "" unless txt.respond_to?(:to_s)
|
172
|
+
|
173
|
+
txt = txt.to_s.strip
|
174
|
+
txt = txt[0...length] + " ..." if txt.length > length
|
175
|
+
|
176
|
+
txt
|
177
|
+
end
|
178
|
+
|
107
179
|
##
|
108
180
|
# Resets level, if lvl (input) is within accepted range.
|
109
181
|
#
|
110
182
|
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
111
183
|
#
|
112
|
-
# @return [
|
184
|
+
# @return [DEBUG, INFO, WARN, ERROR, FATAL] updated/current level
|
113
185
|
def reset(lvl = DEBUG)
|
114
186
|
return @@level unless lvl.respond_to?(:to_i)
|
115
187
|
|
@@ -129,13 +201,13 @@ module OSlg
|
|
129
201
|
# @example A user warning
|
130
202
|
# log(WARN, "Surface area < 100cm2")
|
131
203
|
#
|
132
|
-
# @return [
|
204
|
+
# @return [DEBUG, INFO, WARN, ERROR, FATAL] updated/current status
|
133
205
|
def log(lvl = DEBUG, message = "")
|
134
206
|
return @@status unless lvl.respond_to?(:to_i)
|
135
207
|
return @@status unless message.respond_to?(:to_s)
|
136
208
|
|
137
209
|
lvl = lvl.to_i
|
138
|
-
message = message.to_s
|
210
|
+
message = message.to_s
|
139
211
|
return @@status if lvl < DEBUG
|
140
212
|
return @@status if lvl > FATAL
|
141
213
|
return @@status if lvl < @@level
|
@@ -152,7 +224,7 @@ module OSlg
|
|
152
224
|
# @param id [#to_s] 'invalid object' identifier
|
153
225
|
# @param mth [#to_s] calling method identifier
|
154
226
|
# @param ord [#to_i] calling method argument order number of obj (optional)
|
155
|
-
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
227
|
+
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
156
228
|
# @param res what to return (optional)
|
157
229
|
#
|
158
230
|
# @example An invalid argument, logging a FATAL error, returning FALSE
|
@@ -166,23 +238,18 @@ module OSlg
|
|
166
238
|
return res unless ord.respond_to?(:to_i)
|
167
239
|
return res unless lvl.respond_to?(:to_i)
|
168
240
|
|
169
|
-
id = id.to_s.strip
|
170
|
-
mth = mth.to_s.strip
|
171
241
|
ord = ord.to_i
|
172
242
|
lvl = lvl.to_i
|
173
|
-
|
174
|
-
|
243
|
+
id = trim(id)
|
244
|
+
mth = trim(mth)
|
175
245
|
return res if id.empty?
|
176
|
-
|
177
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
178
246
|
return res if mth.empty?
|
247
|
+
return res if lvl < DEBUG
|
248
|
+
return res if lvl > FATAL
|
179
249
|
|
180
250
|
msg = "Invalid '#{id}' "
|
181
251
|
msg += "arg ##{ord} " if ord > 0
|
182
252
|
msg += "(#{mth})"
|
183
|
-
return res if lvl < DEBUG
|
184
|
-
return res if lvl > FATAL
|
185
|
-
|
186
253
|
log(lvl, msg)
|
187
254
|
|
188
255
|
res
|
@@ -197,7 +264,7 @@ module OSlg
|
|
197
264
|
# @param obj the object to validate
|
198
265
|
# @param cl [Class] target class
|
199
266
|
# @param mth [#to_s] calling method identifier (optional)
|
200
|
-
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
267
|
+
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
201
268
|
# @param res what to return (optional)
|
202
269
|
#
|
203
270
|
# @example A mismatched argument instance/class
|
@@ -207,26 +274,20 @@ module OSlg
|
|
207
274
|
# @return [nil] if user hasn't provided an object to return
|
208
275
|
def mismatch(id = "", obj = nil, cl = nil, mth = "", lvl = DEBUG, res = nil)
|
209
276
|
return res unless id.respond_to?(:to_s)
|
277
|
+
return res unless mth.respond_to?(:to_s)
|
210
278
|
return res unless cl.is_a?(Class)
|
211
279
|
return res if obj.is_a?(cl)
|
212
|
-
return res unless mth.respond_to?(:to_s)
|
213
280
|
return res unless lvl.respond_to?(:to_i)
|
214
281
|
|
215
|
-
id = id.to_s.strip
|
216
|
-
mth = mth.to_s.strip
|
217
282
|
lvl = lvl.to_i
|
218
|
-
|
219
|
-
|
283
|
+
id = trim(id)
|
284
|
+
mth = trim(mth)
|
220
285
|
return res if id.empty?
|
221
|
-
|
222
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
223
286
|
return res if mth.empty?
|
224
|
-
|
225
|
-
msg = "'#{id}' #{obj.class}? expecting #{cl} (#{mth})"
|
226
287
|
return res if lvl < DEBUG
|
227
288
|
return res if lvl > FATAL
|
228
289
|
|
229
|
-
log(lvl,
|
290
|
+
log(lvl, "'#{id}' #{obj.class}? expecting #{cl} (#{mth})")
|
230
291
|
|
231
292
|
res
|
232
293
|
end
|
@@ -239,7 +300,7 @@ module OSlg
|
|
239
300
|
# @param hsh [Hash] hash to validate
|
240
301
|
# @param key missing key
|
241
302
|
# @param mth [#to_s] calling method identifier
|
242
|
-
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
303
|
+
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
243
304
|
# @param res what to return (optional)
|
244
305
|
#
|
245
306
|
# @example A missing Hash key
|
@@ -254,21 +315,15 @@ module OSlg
|
|
254
315
|
return res unless mth.respond_to?(:to_s)
|
255
316
|
return res unless lvl.respond_to?(:to_i)
|
256
317
|
|
257
|
-
id = id.to_s.strip
|
258
|
-
mth = mth.to_s.strip
|
259
318
|
lvl = lvl.to_i
|
260
|
-
|
261
|
-
|
319
|
+
id = trim(id)
|
320
|
+
mth = trim(mth)
|
262
321
|
return res if id.empty?
|
263
|
-
|
264
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
265
322
|
return res if mth.empty?
|
266
|
-
|
267
|
-
msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
|
268
323
|
return res if lvl < DEBUG
|
269
324
|
return res if lvl > FATAL
|
270
325
|
|
271
|
-
log(lvl,
|
326
|
+
log(lvl, "Missing '#{key}' key in '#{id}' Hash (#{mth})")
|
272
327
|
|
273
328
|
res
|
274
329
|
end
|
@@ -278,7 +333,7 @@ module OSlg
|
|
278
333
|
#
|
279
334
|
# @param id [#to_s] empty object identifier
|
280
335
|
# @param mth [#to_s] calling method identifier
|
281
|
-
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
336
|
+
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
282
337
|
# @param res what to return (optional)
|
283
338
|
#
|
284
339
|
# @example An uninitialized variable, logging an ERROR, returning FALSE
|
@@ -291,21 +346,15 @@ module OSlg
|
|
291
346
|
return res unless mth.respond_to?(:to_s)
|
292
347
|
return res unless lvl.respond_to?(:to_i)
|
293
348
|
|
294
|
-
id = id.to_s.strip
|
295
|
-
mth = mth.to_s.strip
|
296
349
|
lvl = lvl.to_i
|
297
|
-
|
298
|
-
|
350
|
+
id = trim(id)
|
351
|
+
mth = trim(mth)
|
299
352
|
return res if id.empty?
|
300
|
-
|
301
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
302
353
|
return res if mth.empty?
|
303
|
-
|
304
|
-
msg = "Empty '#{id}' (#{mth})"
|
305
354
|
return res if lvl < DEBUG
|
306
355
|
return res if lvl > FATAL
|
307
356
|
|
308
|
-
log(lvl,
|
357
|
+
log(lvl, "Empty '#{id}' (#{mth})")
|
309
358
|
|
310
359
|
res
|
311
360
|
end
|
@@ -315,7 +364,7 @@ module OSlg
|
|
315
364
|
#
|
316
365
|
# @param id [#to_s] zero object identifier
|
317
366
|
# @param mth [#to_s] calling method identifier
|
318
|
-
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
|
367
|
+
# @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
319
368
|
# @param res what to return (optional)
|
320
369
|
#
|
321
370
|
# @example A near-zero variable
|
@@ -328,22 +377,16 @@ module OSlg
|
|
328
377
|
return res unless mth.respond_to?(:to_s)
|
329
378
|
return res unless lvl.respond_to?(:to_i)
|
330
379
|
|
331
|
-
id = id.to_s.strip
|
332
|
-
mth = mth.to_s.strip
|
333
380
|
ord = ord.to_i
|
334
381
|
lvl = lvl.to_i
|
335
|
-
|
336
|
-
|
382
|
+
id = trim(id)
|
383
|
+
mth = trim(mth)
|
337
384
|
return res if id.empty?
|
338
|
-
|
339
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
340
385
|
return res if mth.empty?
|
341
|
-
|
342
|
-
msg = "Zero '#{id}' (#{mth})"
|
343
386
|
return res if lvl < DEBUG
|
344
387
|
return res if lvl > FATAL
|
345
388
|
|
346
|
-
log(lvl,
|
389
|
+
log(lvl, "Zero '#{id}' (#{mth})")
|
347
390
|
|
348
391
|
res
|
349
392
|
end
|
@@ -366,22 +409,15 @@ module OSlg
|
|
366
409
|
return res unless mth.respond_to?(:to_s)
|
367
410
|
return res unless lvl.respond_to?(:to_i)
|
368
411
|
|
369
|
-
id = id.to_s.strip
|
370
|
-
mth = mth.to_s.strip
|
371
|
-
ord = ord.to_i
|
372
412
|
lvl = lvl.to_i
|
373
|
-
|
374
|
-
|
413
|
+
id = trim(id)
|
414
|
+
mth = trim(mth)
|
375
415
|
return res if id.empty?
|
376
|
-
|
377
|
-
mth = mth[0...60] + " ..." if mth.length > 60
|
378
416
|
return res if mth.empty?
|
379
|
-
|
380
|
-
msg = "Negative '#{id}' (#{mth})"
|
381
417
|
return res if lvl < DEBUG
|
382
418
|
return res if lvl > FATAL
|
383
419
|
|
384
|
-
log(lvl,
|
420
|
+
log(lvl, "Negative '#{id}' (#{mth})")
|
385
421
|
|
386
422
|
res
|
387
423
|
end
|
@@ -389,7 +425,7 @@ module OSlg
|
|
389
425
|
##
|
390
426
|
# Resets log status and entries.
|
391
427
|
#
|
392
|
-
# @return [Integer] current level
|
428
|
+
# @return [Integer] current log level
|
393
429
|
def clean!
|
394
430
|
@@status = 0
|
395
431
|
@@logs = []
|
data/lib/oslg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oslg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Bourgeois
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,7 @@ licenses:
|
|
76
76
|
- BSD-3-Clause
|
77
77
|
metadata:
|
78
78
|
homepage_uri: https://github.com/rd2/oslg
|
79
|
-
source_code_uri: https://github.com/rd2/oslg/tree/v0.2.
|
79
|
+
source_code_uri: https://github.com/rd2/oslg/tree/v0.2.10
|
80
80
|
bug_tracker_uri: https://github.com/rd2/oslg/issues
|
81
81
|
post_install_message:
|
82
82
|
rdoc_options: []
|