dbg_tags 1.0.0 → 1.0.1
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/dbg_tags.rb +137 -49
- data/spec/01_tag_spec.rb +85 -0
- metadata +9 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0665b5e4280aea457cd828d6cfab8730c71502fc8e32daae72904bd60abe87b3
|
4
|
+
data.tar.gz: 7ad792027dc763687f856bdae2126d5ad8816b949dc4b16365420c78c9b3aa10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf3f313c0f1c54978f2b9e9538e99c80e8a9a3148fb85f03c5f63b87305db344e508745fce939e5dc94e32550a058515986cef7c282950450c506a61748e82c
|
7
|
+
data.tar.gz: 5bb9dafd4b182778c9e6ff07208cae8f9b6b713eef2c4ab4fef89c8d20e973faf06a9e442b28d627cc1180e4e6459250bb1a8f0431b7cd259d5e5c486652db57
|
data/lib/dbg_tags.rb
CHANGED
@@ -1,62 +1,112 @@
|
|
1
1
|
|
2
|
-
# Usage:
|
2
|
+
# @example Usage:
|
3
|
+
#
|
4
|
+
# # enabling
|
5
|
+
# # -----------
|
3
6
|
# require 'dbg_tags'
|
4
|
-
#
|
5
|
-
# # :err should be used for fail states and paranoia stuff
|
6
|
-
# Tag.log 'text' # prints very important messages only
|
7
|
-
# Tag.trc 'text' # default level, method entries, for example
|
8
|
-
# Tag.val 'text' # prints more details
|
9
|
-
# Tag.dtl 'text' # prints megabytes of details
|
10
|
-
# Tag.enable :log # enables log,trc,val,dtl tags for :generic
|
11
|
-
# Tag.enable :dtl # only enables :dtl calls
|
12
|
-
# Tag.enable :err # enable ALL :generic tags
|
13
|
-
# Tag.err :feature, 'FAILURE'
|
14
|
-
# Tag.log :feature, 'log me'
|
15
|
-
# Tag.trc :feature, 'called method'
|
16
|
-
# Tag.val(:feature) { "text#{expr}" }
|
17
|
-
# Tag.dtl(:feature) { "text#{very complicated expr}" }
|
18
|
-
# Tag.err(:test) { raise 'aaaarg' if paranoia_failure }
|
19
|
-
# Tag.err(:test) { raise 'CANTHAPPEN' if paranoia_failure }
|
7
|
+
#
|
20
8
|
# Tag.enable :feature1, :feature2..., featureN: :log, featureO: :val, ...
|
21
9
|
# Tag.enable feature1: :trc, feature2: :val
|
22
10
|
# Tag.enable feature: Tag::TRC
|
23
|
-
# Tag.enable :
|
11
|
+
# Tag.enable :dtl # enables ALL logging for :generic
|
12
|
+
# Tag.enable :val # enables val+trc+log+err for :generic only
|
13
|
+
# Tag.enable :trc # enables trc+log+err for :generic only
|
14
|
+
# Tag.enable :log # enables log+err tags for :generic
|
15
|
+
# Tag.enable :err # enables err tags for :generic
|
24
16
|
# Tag.enable # sets :generic to :trc
|
25
17
|
# Tag.enable(...) do ... end
|
26
18
|
# Tag.enable feature: nil
|
27
19
|
# Tag.enable feature: :nil
|
28
20
|
# Tag.enable all: :err # :all is a default for ALL systems, including :generic
|
29
21
|
# Tag.enable test: :err # switch on paranoia checking
|
22
|
+
# Tag.enable feature: '>=trc' # make sure at least level trc
|
23
|
+
#
|
24
|
+
# # logging
|
25
|
+
# # -----------
|
26
|
+
# Tag.err 'text', short for Tag.err(:generic) 'text'
|
27
|
+
# # :err should be used for fail states and paranoia stuff
|
28
|
+
# Tag.log 'text' # prints very important messages only
|
29
|
+
# Tag.trc 'text' # default level, method entries, for example
|
30
|
+
# Tag.val 'text' # prints more details
|
31
|
+
# Tag.dtl 'text' # likely prints megabytes of details
|
32
|
+
# Tag.err :feature, 'FAILURE'
|
33
|
+
# Tag.log :feature, 'log me'
|
34
|
+
# Tag.trc :feature, 'called method'
|
35
|
+
# Tag.val(:feature) { "text#{expr}" }
|
36
|
+
# Tag.dtl(:feature) { "text#{very complicated expr}" }
|
37
|
+
# Tag.err(:test) { raise 'aaaarg' if complex_paranoia_failure }
|
38
|
+
# Tag.err(:test) { raise 'CANTHAPPEN' if complex_paranoia_failure }
|
39
|
+
|
30
40
|
module Tag
|
31
41
|
|
42
|
+
# the default is :trc
|
32
43
|
TAG_DEFAULT_LEVEL = 3
|
44
|
+
|
45
|
+
# :all overrides the minimum level on ALL tags in the system
|
33
46
|
TAG_FEATURE_ALL = :all
|
47
|
+
|
48
|
+
# :generic is the default feature, if left unspecified
|
34
49
|
TAG_FEATURE_GENERIC = :generic
|
50
|
+
|
51
|
+
# lowest level. No output
|
35
52
|
NONE = 0
|
53
|
+
|
54
|
+
# level 1. Only error situation should use this
|
36
55
|
ERR = 1
|
56
|
+
|
57
|
+
# level 2. Only very important information
|
37
58
|
LOG = 2
|
59
|
+
|
60
|
+
# level 3. Mostly used for method entries
|
38
61
|
TRC = 3
|
62
|
+
|
63
|
+
# level 4. Mostly used dumping of attribute values
|
39
64
|
VAL = 4
|
65
|
+
|
66
|
+
# level 5. Mostly used for exhaustive dumping of attribute values and minor details
|
40
67
|
DTL = 5
|
68
|
+
|
41
69
|
# nil and :nil will both map to NONE
|
42
70
|
TAG_MAPPING = { none: NONE, err: ERR, log: LOG, trc: TRC, val: VAL, dtl: DTL,
|
43
71
|
nil: NONE,
|
44
72
|
nil => NONE
|
45
73
|
} # TAG_MAPPING
|
46
74
|
|
47
|
-
# @@enabled[:feature] => 0..5
|
75
|
+
# @@enabled[:feature] => 0..5
|
48
76
|
@@enabled = {}
|
49
77
|
@@stream = STDERR
|
50
78
|
|
51
79
|
module InstanceMethods
|
52
80
|
@@inside = false
|
53
81
|
|
82
|
+
# @param feature [Symbol,nil] Subsystem to print logging for. Fully dynamic/free
|
83
|
+
# @param msg [String,nil]
|
84
|
+
# @note feature and msg can be switched
|
85
|
+
# @param block [Proc,nil] If set the result overrides and msg passed.
|
86
|
+
# The call is silently ignored if called from inside another Tag block (likely
|
87
|
+
# a sign of a stack overflow in process).
|
88
|
+
# The call is silently ignored if the current tag level is too low.
|
89
|
+
# For trc it should be trc or val or dtl to actually print something.
|
90
|
+
# @!method trc feature = TAG_FEATURE_GENERIC, msg = '', &block
|
91
|
+
|
92
|
+
# see trc
|
93
|
+
# !method err feature = TAG_FEATURE_GENERIC, msg = '', &block
|
94
|
+
|
95
|
+
# see trc
|
96
|
+
# !method log feature = TAG_FEATURE_GENERIC, msg = '', &block
|
97
|
+
|
98
|
+
# see trc
|
99
|
+
# !method val feature = TAG_FEATURE_GENERIC, msg = '', &block
|
100
|
+
|
101
|
+
# see trc
|
102
|
+
# !method dtl feature = TAG_FEATURE_GENERIC, msg = '', &block
|
103
|
+
|
54
104
|
TAG_MAPPING.each do |meth, lev|
|
55
105
|
next if lev == NONE
|
56
106
|
define_method meth do |feature = TAG_FEATURE_GENERIC, msg = '', &msg_block|
|
57
107
|
msg, feature = feature, TAG_FEATURE_GENERIC if String === feature
|
58
108
|
#STDERR.puts "DEBUGTAG #{meth}. feature=#{feature}, level=#{Tag.level(feature)}, lev=#{lev}"
|
59
|
-
return if @@inside || (Tag.level(feature) ||
|
109
|
+
return if @@inside || (Tag.level(feature) || Tag::NONE) < lev
|
60
110
|
# either msg OR msg_block must be set
|
61
111
|
if msg_block
|
62
112
|
prev_inside = @@inside
|
@@ -84,39 +134,70 @@ module Tag
|
|
84
134
|
|
85
135
|
end # module Tag::InstanceMethods
|
86
136
|
|
87
|
-
|
137
|
+
extend InstanceMethods
|
138
|
+
include InstanceMethods
|
139
|
+
|
140
|
+
class << self
|
141
|
+
private # class methods of Tag
|
88
142
|
|
89
|
-
|
90
|
-
|
143
|
+
# @param level_spec [Integer,Symbol,String]
|
144
|
+
# @param feature [Symbol]
|
145
|
+
# @return [0..5]
|
146
|
+
def debunk_level level_spec, feature
|
147
|
+
# raise 'AARG' unless Symbol === feature
|
148
|
+
# OK STDERR.puts "DEBUNK: level_spec=#{level_spec.inspect}, feature=#{feature.inspect}"
|
149
|
+
case level_spec
|
150
|
+
when 0..5 then return level_spec
|
151
|
+
when Symbol
|
152
|
+
r = TAG_MAPPING[level_spec] and return r
|
153
|
+
when /\A(err|log|trc|val|dtl)\z/
|
154
|
+
return TAG_MAPPING[level_spec.to_sym]
|
155
|
+
when /\A>=(err|log|trc|val|dtl)\z/
|
156
|
+
eff_lev = level feature
|
157
|
+
new_lev = TAG_MAPPING[level_spec[2..].to_sym]
|
158
|
+
# OK STDERR.puts "level_spec=#{level_spec}, feature=#{feature.inspect},eff_lev=#{eff_lev},new_lev=#{new_lev}"
|
159
|
+
return [eff_lev, new_lev].max
|
160
|
+
end # case
|
161
|
+
raise ArgumentError, "bad level #{level_spec.inspect}"
|
162
|
+
end # Tag::debunk_level
|
91
163
|
|
164
|
+
public # class methods of Tag
|
165
|
+
|
166
|
+
# @param features [<Symbol>]
|
92
167
|
# enable :feature, ...[, feature: level, ...] [block]
|
93
|
-
# :generic is NO LONGER IMPLICETELY ENABLED as of version
|
168
|
+
# :generic is NO LONGER IMPLICETELY ENABLED as of version 1.0.0
|
94
169
|
# Use :all to set a default for all features not mentioned otherwise
|
95
170
|
# Integers in range 1..5 can be used as level or the constants ERR,LOG,TRC,VAL,DTL
|
96
171
|
# or the symbols :err, :log, :trc, :val and :dtl
|
172
|
+
# Strings can be used in the shape of 'err' or '>=err' etc.
|
173
|
+
# If '>=LVL' is used the level will not lower, if already set in an outer block.
|
97
174
|
# If no level is specified for a feature the default is :trc (== TRC == 3)
|
98
175
|
# use nil or :none to disable all tags, even the ERR level ones.
|
99
176
|
#
|
100
177
|
# enable performs a merge with an existing enable.
|
101
|
-
def
|
102
|
-
org_enabled = @@enabled.dup
|
103
|
-
|
104
|
-
|
105
|
-
when
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
@@enabled[TAG_FEATURE_GENERIC] = s
|
111
|
-
else
|
112
|
-
if TAG_MAPPING[s]
|
113
|
-
@@enabled[TAG_FEATURE_GENERIC] = TAG_MAPPING[s]
|
178
|
+
def enable *features, **opts
|
179
|
+
org_enabled = @@enabled.dup # to restore the state at the end (unused unless block_given)
|
180
|
+
features.each do |feature|
|
181
|
+
case feature
|
182
|
+
when 0..5 # not a feature, apply to :generic
|
183
|
+
@@enabled[TAG_FEATURE_GENERIC] = feature
|
184
|
+
when Symbol
|
185
|
+
if TAG_MAPPING[feature] # not a feature
|
186
|
+
@@enabled[TAG_FEATURE_GENERIC] = TAG_MAPPING[feature]
|
114
187
|
else
|
115
|
-
@@enabled[
|
188
|
+
@@enabled[feature] = TAG_DEFAULT_LEVEL
|
116
189
|
end
|
117
|
-
|
190
|
+
when String
|
191
|
+
@@enabled[TAG_FEATURE_GENERIC] = debunk_level feature, TAG_FEATURE_GENERIC
|
192
|
+
else
|
193
|
+
raise ArgumentError "bad level #{feature.inspect}"
|
194
|
+
end # case
|
118
195
|
end # each
|
119
|
-
|
196
|
+
opts.each do |feature, level|
|
197
|
+
# OK STDERR.puts "OPTION!!!!!!!!!!!!!!!!!, calling debunk_level"
|
198
|
+
@@enabled[feature] = debunk_level level, feature
|
199
|
+
end
|
200
|
+
if features.empty? && opts.empty?
|
120
201
|
@@enabled[TAG_FEATURE_GENERIC] = TAG_DEFAULT_LEVEL
|
121
202
|
end
|
122
203
|
if block_given?
|
@@ -130,16 +211,23 @@ module Tag
|
|
130
211
|
end # block_given?
|
131
212
|
end # Tag.enable
|
132
213
|
|
133
|
-
#
|
134
|
-
def
|
135
|
-
|
214
|
+
# @return [{Symbol=>0..5}] Keys are the features
|
215
|
+
def enabled; @@enabled; end
|
216
|
+
|
217
|
+
# @return [IO] By default this is STDERR
|
218
|
+
def stream; @@stream; end
|
136
219
|
|
137
|
-
#
|
138
|
-
|
220
|
+
# @param val [IO]
|
221
|
+
# Override the output stream.
|
222
|
+
def stream= val; @@stream = val; end
|
139
223
|
|
140
|
-
#
|
141
|
-
|
224
|
+
# @param feature [Symbol]
|
225
|
+
# @return [0..5] Current effective level for feature.
|
226
|
+
# 2023-08-14 no longer returns nil
|
227
|
+
def level feature; @@enabled[feature] || @@enabled[TAG_FEATURE_ALL] || Tag::NONE; end
|
142
228
|
|
143
|
-
#
|
144
|
-
|
229
|
+
# @param feature [Symbol]
|
230
|
+
# @return [bool] Reflects explicit enable calls only. The :all feature is IGNORED
|
231
|
+
def enabled? feature; (@@enabled[feature] || NONE) > NONE; end
|
232
|
+
end # singleton class Tag
|
145
233
|
end # module Tag
|
data/spec/01_tag_spec.rb
CHANGED
@@ -178,4 +178,89 @@ describe 'tag' do
|
|
178
178
|
# however, it only works with LAZY calls.
|
179
179
|
# def to_s; Tag.trc "HERE in #{self}"; super; end
|
180
180
|
# will OBVIOUSLY cause a stack overflow.
|
181
|
+
#
|
182
|
+
|
183
|
+
context 'Nested levels' do
|
184
|
+
it 'overwrites the level set in outer temporarily (tag_200)' do
|
185
|
+
Tag.enable nest: :val do
|
186
|
+
expect(Tag.level :nest).to be Tag::VAL
|
187
|
+
Tag.enable nest: 'trc' do
|
188
|
+
expect(Tag.level :nest).to be Tag::TRC
|
189
|
+
end
|
190
|
+
expect(Tag.level :nest).to be Tag::VAL
|
191
|
+
end
|
192
|
+
end # it
|
193
|
+
|
194
|
+
it 'raises the level set in outer temporarily if >= is used (tag_201)' do
|
195
|
+
Tag.enable nest: :err do
|
196
|
+
expect(Tag.level :nest).to be Tag::ERR
|
197
|
+
Tag.enable nest: '>=trc' do
|
198
|
+
expect(Tag.level :nest).to be Tag::TRC
|
199
|
+
end
|
200
|
+
expect(Tag.level :nest).to be Tag::ERR
|
201
|
+
end
|
202
|
+
end # it
|
203
|
+
|
204
|
+
it 'ONLY raises the level set in outer temporarily if >= is used (tag_202)' do
|
205
|
+
Tag.enable nest: :trc do
|
206
|
+
expect(Tag.level :nest).to be Tag::TRC
|
207
|
+
Tag.enable nest: '>=err' do
|
208
|
+
expect(Tag.level :nest).to be Tag::TRC
|
209
|
+
end
|
210
|
+
expect(Tag.level :nest).to be Tag::TRC
|
211
|
+
end
|
212
|
+
end # it
|
213
|
+
|
214
|
+
it 'raises the level set in outer temporarily if >= is used (tag_201.b)' do
|
215
|
+
Tag.enable :err do
|
216
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::ERR
|
217
|
+
Tag.enable '>=trc' do
|
218
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::TRC
|
219
|
+
end
|
220
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::ERR
|
221
|
+
end
|
222
|
+
end # it
|
223
|
+
|
224
|
+
it 'ONLY raises the level set in outer temporarily if >= is used (tag_202.b)' do
|
225
|
+
Tag.enable :trc do
|
226
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::TRC
|
227
|
+
Tag.enable nest: '>=err' do
|
228
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::TRC
|
229
|
+
end
|
230
|
+
expect(Tag.level Tag::TAG_FEATURE_GENERIC).to be Tag::TRC
|
231
|
+
end
|
232
|
+
end # it
|
233
|
+
|
234
|
+
it 'takes :all into consideration when >= is used (tag_205)' do
|
235
|
+
Tag.enable all: :log do
|
236
|
+
expect(Tag.level :nest).to be Tag::LOG
|
237
|
+
Tag.enable nest: '>=err' do
|
238
|
+
expect(Tag.level :nest).to be Tag::LOG
|
239
|
+
end
|
240
|
+
expect(Tag.level :nest).to be Tag::LOG
|
241
|
+
Tag.enable nest: '>=trc' do
|
242
|
+
expect(Tag.level :nest).to be Tag::TRC
|
243
|
+
end
|
244
|
+
expect(Tag.level :nest).to be Tag::LOG
|
245
|
+
end
|
246
|
+
end # it
|
247
|
+
end # context 'Nested levels'
|
248
|
+
|
249
|
+
it 'does not allow levels out of range (tag_900)' do
|
250
|
+
expect do
|
251
|
+
Tag.enable nest: 24
|
252
|
+
end.to raise_error ArgumentError, /bad level/i
|
253
|
+
expect do
|
254
|
+
Tag.enable nest: -2
|
255
|
+
end.to raise_error ArgumentError, /bad level/i
|
256
|
+
end # it
|
257
|
+
|
258
|
+
it 'does not allow made up levels (tag_901)' do
|
259
|
+
expect do
|
260
|
+
Tag.enable nest: :foo
|
261
|
+
end.to raise_error ArgumentError, /bad level/i
|
262
|
+
expect do
|
263
|
+
Tag.enable nest: '>=foo'
|
264
|
+
end.to raise_error ArgumentError, /bad level/i
|
265
|
+
end # it
|
181
266
|
end # describe
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbg_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Brazwick
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,25 +52,9 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.18'
|
55
|
-
description:
|
56
|
-
|
57
|
-
|
58
|
-
file, method and linenumber\n Tag.trc :feature, 'a message' # only called if
|
59
|
-
:feature enabled.\n Tag.err 'msg' # Triggered when :generic feature is set
|
60
|
-
to at \n # least :err level.\n # The levels
|
61
|
-
are :err, :log, :trc, :val and :dtl, \n # in that order\n Tag.dtl
|
62
|
-
:complex do \"val = #{expensive.method.call}\" end\n Tag.dtl(:complex) { \"val
|
63
|
-
= #{expensive.method.call}\" }\n\t # use lazy evaluation with a block.\n #
|
64
|
-
The block expression is printed using to_s.\n Tag.dtl(:complex) {} # same as
|
65
|
-
Tag.dtl :complex \n# At the start of your application enable the desired dump-level.\n
|
66
|
-
\ Tag.enable\t# Same as Tag.enable generic: :trc\n #
|
67
|
-
That is enables levels <=:trc\n Tag.enable :val # enable :generic tags at
|
68
|
-
<=:val levels\n Tag.enable :feature1, :feat2, ... # enables given features
|
69
|
-
on <=:trc\n Tag.enable :feature1, :feat2, feat3: :dtl, all: :err\n\t# Set :feature1,
|
70
|
-
:feat2, and :generic to <=:trc, :feat3 to :dtl\n\t# and ANY OTHER feature to only
|
71
|
-
:err. \n Tag.enable feature: :err \n Tag.enable feature: :dtl # so ALL
|
72
|
-
tags with feature :feature\n Tag.err(:feature) { raise 'aaaarg' if expensive_check_fails?
|
73
|
-
}\n"
|
55
|
+
description: |
|
56
|
+
debug 'tags' in your code can be switched on/off using features and levels.
|
57
|
+
See README.md
|
74
58
|
email: eugenebrazwick@gmail.com
|
75
59
|
executables: []
|
76
60
|
extensions: []
|
@@ -82,7 +66,7 @@ homepage: https://github.com/Eugene-Brazwick/dbg_tags
|
|
82
66
|
licenses:
|
83
67
|
- GPL-3.0
|
84
68
|
metadata: {}
|
85
|
-
post_install_message:
|
69
|
+
post_install_message:
|
86
70
|
rdoc_options: []
|
87
71
|
require_paths:
|
88
72
|
- lib
|
@@ -97,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
81
|
- !ruby/object:Gem::Version
|
98
82
|
version: '0'
|
99
83
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
101
|
-
signing_key:
|
84
|
+
rubygems_version: 3.3.5
|
85
|
+
signing_key:
|
102
86
|
specification_version: 4
|
103
87
|
summary: a versatile dynamic debug tracing system
|
104
88
|
test_files:
|