trace-util-adv 0.2.4 → 0.3.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.
- data/TODO.txt +18 -2
- data/VERSION +1 -1
- data/lib/appenders/appender.rb +1 -1
- data/lib/appenders/base_appender.rb +18 -20
- data/lib/appenders/include.rb +2 -2
- data/lib/appenders/types/html_appender.rb +1 -1
- data/lib/appenders/types/logger_appender.rb +1 -1
- data/lib/appenders/types/xml_appender.rb +1 -1
- data/lib/extensions/hash_extensions.rb +41 -19
- data/lib/extensions/hash_rule_extensions.rb +4 -0
- data/lib/extensions/symbol_extensions.rb +7 -5
- data/lib/filters/composite/composite_class_filter.rb +1 -0
- data/lib/filters/composite/composite_module_filter.rb +1 -0
- data/lib/filters/executor/filter_exec.rb +6 -2
- data/lib/filters/filter.rb +12 -17
- data/lib/filters/filter_factory.rb +1 -1
- data/lib/filters/filter_mappings.rb +4 -2
- data/lib/filters/include.rb +4 -8
- data/lib/filters/list/list_instance_var_filter.rb +1 -0
- data/lib/filters/name_filter.rb +13 -0
- data/lib/filters/simple/argument_filter.rb +2 -1
- data/lib/filters/simple/class_filter.rb +1 -1
- data/lib/filters/simple/instance_var_filter.rb +9 -6
- data/lib/filters/simple/method_filter.rb +1 -0
- data/lib/filters/simple/module_filter.rb +6 -3
- data/lib/rules/rule_match.rb +5 -4
- data/lib/targets/file_target.rb +11 -0
- data/lib/templates/base_template.rb +11 -12
- data/lib/templates/html_template.rb +35 -36
- data/lib/templates/string_template.rb +0 -1
- data/lib/templates/template_mappings.rb +4 -4
- data/lib/templates/xml_template.rb +0 -1
- data/lib/trace-util-adv.rb +36 -20
- data/lib/trace_calls/trace_ext.rb +4 -17
- data/test/action_handler/include.rb +4 -0
- data/test/action_handler/test_action_handler.rb +1 -2
- data/test/action_handler/test_create_action_handler.rb +6 -9
- data/test/appenders/include.rb +4 -0
- data/test/appenders/test_appender_templates.rb +57 -0
- data/test/appenders/test_create_appender.rb +9 -10
- data/test/extensions/include.rb +4 -0
- data/test/extensions/test_filters_creation.rb +4 -28
- data/test/extensions/test_hash_extensions.rb +44 -47
- data/test/extensions/test_hash_filter_extensions.rb +46 -29
- data/test/extensions/test_set_context.rb +9 -11
- data/test/extensions/test_string_extensions.rb +1 -3
- data/test/extensions/test_symbol_extensions.rb +2 -4
- data/test/filters/chain/test_filters_chain.rb +1 -51
- data/test/filters/composite/test_composite_class_filter.rb +1 -3
- data/test/filters/composite/test_composite_module_filter.rb +1 -3
- data/test/filters/composite/test_composite_var_filter.rb +8 -11
- data/test/filters/executor/test_filter_exec.rb +1 -3
- data/test/filters/include.rb +8 -0
- data/test/filters/msg_context/test_custom_filters.rb +13 -14
- data/test/filters/simple/test_base_filter.rb +8 -6
- data/test/filters/simple/test_class_filter.rb +1 -3
- data/test/filters/simple/test_instancevar_filter.rb +5 -9
- data/test/filters/simple/test_method_filter.rb +4 -9
- data/test/filters/simple/test_module_filter.rb +13 -10
- data/test/samples/sample_composite_filters.rb +15 -12
- data/test/targets/test_create_targets.rb +21 -0
- data/test/templates/include.rb +4 -0
- data/test/templates/test_create_templates.rb +23 -0
- data/test/templates/test_exec_templates.rb +6 -0
- data/test/trace_calls/include.rb +4 -0
- data/test/trace_calls/test_configure_.rb +17 -14
- data/test/trace_calls/tracing/test_html_tracing.rb +2 -3
- data/test/trace_calls/tracing/test_logger_tracing.rb +5 -4
- data/test/trace_calls/tracing/test_stream_tracing.rb +2 -3
- data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +2 -3
- data/test/trace_calls/tracing/test_xml_tracing.rb +2 -3
- data/trace-util-adv.gemspec +14 -6
- metadata +13 -5
- data/test/appenders/test_appender_tracers.rb +0 -56
- data/test/tracers/test_create_tracers.rb +0 -46
- data/test/tracers/test_exec_tracers.rb +0 -11
data/TODO.txt
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
TODO:
|
2
2
|
----
|
3
|
-
-
|
4
|
-
-
|
3
|
+
- Clean up Appenders, Templates and Targets
|
4
|
+
- Convenience Appenders
|
5
|
+
- LogFile
|
6
|
+
- HtmlFile
|
7
|
+
- XmlFile
|
8
|
+
- HtmlString
|
9
|
+
- XmlString
|
10
|
+
- Logger
|
11
|
+
|
12
|
+
- Targets
|
13
|
+
- File
|
14
|
+
- String
|
15
|
+
- Stream (STDOUT, STDERR)
|
16
|
+
- Stack
|
17
|
+
|
18
|
+
- Add listener to Target?
|
19
|
+
|
20
|
+
- Simplify with Listener model?
|
5
21
|
|
6
22
|
---
|
7
23
|
Add time to context for before- and after handle calls. Enable tracing time output
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/appenders/appender.rb
CHANGED
@@ -4,24 +4,24 @@ module Tracing
|
|
4
4
|
include Tracing::FilterUse
|
5
5
|
|
6
6
|
attr_accessor :options
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :templates
|
8
8
|
|
9
9
|
class << self
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :templates
|
11
11
|
|
12
12
|
|
13
|
-
def
|
14
|
-
@
|
15
|
-
@
|
13
|
+
def register_templates(templates = nil)
|
14
|
+
@templates ||= {} # default_templates
|
15
|
+
@templates = @templates.merge!(templates || {})
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
if
|
21
|
-
|
22
|
-
|
23
|
-
elsif
|
24
|
-
|
18
|
+
def create_template(template)
|
19
|
+
templates ||= register_templates
|
20
|
+
if template.kind_of?(Symbol) || template.kind_of?(String)
|
21
|
+
template_class = templates[template.to_sym] || templates[:default]
|
22
|
+
template_class.new
|
23
|
+
elsif template.kind_of? Tracing::BaseTemplate
|
24
|
+
template
|
25
25
|
else
|
26
26
|
nil
|
27
27
|
end
|
@@ -33,18 +33,16 @@ module Tracing
|
|
33
33
|
if init_options.kind_of? Hash
|
34
34
|
@options = init_options[:options] || init_options
|
35
35
|
register_filters(init_options[:filters])
|
36
|
-
|
37
|
-
return if !
|
36
|
+
template = @options[:template] if @options
|
37
|
+
return if !template
|
38
38
|
|
39
|
-
|
40
|
-
@tracer = tracer
|
39
|
+
@template = self.class.create_template(template)
|
41
40
|
elsif init_options.kind_of? Symbol
|
42
|
-
self.class.
|
43
|
-
tracer = self.class.
|
41
|
+
self.class.register_templates
|
42
|
+
tracer = self.class.templates[init_options]
|
44
43
|
return if !tracer
|
45
44
|
|
46
|
-
|
47
|
-
@tracer = tracer
|
45
|
+
@template = self.class.create_template(template)
|
48
46
|
else
|
49
47
|
raise Exception, "Appender must be initialized with Hash"
|
50
48
|
end
|
data/lib/appenders/include.rb
CHANGED
@@ -7,6 +7,7 @@ class Hash
|
|
7
7
|
self[:modules] = cls_name.modules if cls_name && !modules
|
8
8
|
self[:class_name] = cls_name.class_name if cls_name
|
9
9
|
calculate_full_names
|
10
|
+
self
|
10
11
|
end
|
11
12
|
|
12
13
|
def method_name=(name)
|
@@ -85,17 +86,31 @@ class Hash
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
|
-
# return action_handler
|
89
89
|
def appenders
|
90
90
|
appender_list = self[:appenders]
|
91
|
-
appender_list.appenders
|
91
|
+
return appender_list.appenders if appender_list
|
92
|
+
template = self.template
|
93
|
+
if template
|
94
|
+
puts template.inspect
|
95
|
+
else
|
96
|
+
puts "no template"
|
97
|
+
end
|
92
98
|
end
|
93
99
|
|
94
|
-
#
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
100
|
+
# Rework?
|
101
|
+
def appender
|
102
|
+
puts self[:template].inspect
|
103
|
+
# appenders
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# return template
|
108
|
+
def template
|
109
|
+
puts "Template from : #{self.inspect}"
|
110
|
+
template_key = self[:template] || self[:type]
|
111
|
+
template_class = TemplateMappings.defaults[template_key]
|
112
|
+
puts template_class.inspect
|
113
|
+
template_class.new self if template_class
|
99
114
|
end
|
100
115
|
|
101
116
|
def create_filter
|
@@ -103,15 +118,19 @@ class Hash
|
|
103
118
|
hash = self.create_filter_hash || self
|
104
119
|
if hash
|
105
120
|
filter_class = hash.filter_class
|
106
|
-
|
107
|
-
|
121
|
+
if filter_class
|
122
|
+
filter_class.new(hash)
|
123
|
+
else
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
else
|
127
|
+
nil
|
108
128
|
end
|
109
|
-
nil
|
110
129
|
end
|
111
130
|
|
112
131
|
def create_filter_hash
|
113
132
|
# puts "TRY create_filter: " + name_hash.inspect
|
114
|
-
[:module_filter, :class_filter, :method_filter, :vars_filter].each do |symbol|
|
133
|
+
[:module_filter, :class_filter, :method_filter, :vars_filter, :args_filter].each do |symbol|
|
115
134
|
# puts "symbol:" + symbol.to_s
|
116
135
|
res = self.try_create_filter_hash(symbol)
|
117
136
|
# puts "Filter created:" + res.inspect
|
@@ -123,14 +142,14 @@ class Hash
|
|
123
142
|
|
124
143
|
def try_create_filter_hash(symbol)
|
125
144
|
_symbol = has_any_prefix(symbol)
|
126
|
-
puts _symbol.inspect
|
145
|
+
# puts _symbol.inspect
|
127
146
|
return if !_symbol
|
128
147
|
|
129
148
|
prefix = _symbol[:prefix]
|
130
149
|
filter_sym = _symbol[:filter_symbol]
|
131
|
-
|
150
|
+
|
132
151
|
filter_names = self[filter_sym]
|
133
|
-
|
152
|
+
|
134
153
|
rule_symbol = prefix.to_sym.rule
|
135
154
|
{symbol => {rule_symbol => filter_names}}
|
136
155
|
end
|
@@ -142,10 +161,10 @@ class Hash
|
|
142
161
|
end
|
143
162
|
|
144
163
|
def filter_class
|
145
|
-
|
164
|
+
FilterMappings.convenience_map.select do |key, _filter|
|
146
165
|
return _filter.filter_class if self.has_key?(key) || self.has_key?(_filter)
|
147
166
|
end
|
148
|
-
|
167
|
+
FilterMappings.rules_map.select do |key, _filter|
|
149
168
|
return _filter.filter_class if self.has_key? key
|
150
169
|
end
|
151
170
|
nil
|
@@ -154,13 +173,16 @@ class Hash
|
|
154
173
|
protected
|
155
174
|
|
156
175
|
def calculate_full_names
|
157
|
-
|
158
|
-
|
176
|
+
fmm = full_modules_name
|
177
|
+
fcm = full_class_name
|
178
|
+
self[:full_modules_name] = fmm if fmm
|
179
|
+
self[:full_class_name] = fcm if fcm
|
159
180
|
calculate_full_method_name
|
160
181
|
end
|
161
182
|
|
162
183
|
def calculate_full_method_name
|
163
|
-
|
184
|
+
fmn = full_method_name
|
185
|
+
self[:full_method_name] = fmn if fmn
|
164
186
|
end
|
165
187
|
|
166
188
|
def has_prefix(symbol, prefix)
|
@@ -2,6 +2,7 @@ class Hash
|
|
2
2
|
include Tracing::RuleMatch
|
3
3
|
|
4
4
|
def rules_allow_action(name)
|
5
|
+
puts "Hash: rules_allow_action"
|
5
6
|
rule_allow_action(name)
|
6
7
|
end
|
7
8
|
|
@@ -12,6 +13,9 @@ class Hash
|
|
12
13
|
# return a symbol, either - :include, :exclude or :exclude_and_yield, :include_and_yield or :yield (let next filter decide)
|
13
14
|
def rule_allow_action(name)
|
14
15
|
include_rules = self[:include].rule_list
|
16
|
+
|
17
|
+
puts "include_rules: #{include_rules.inspect}, name: #{name}"
|
18
|
+
|
15
19
|
if !include_rules.blank?
|
16
20
|
# puts "Rule include"
|
17
21
|
res = include_rules.matches_any?(name)
|
@@ -4,27 +4,29 @@ class Symbol
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def filter_class
|
7
|
-
mapper =
|
7
|
+
mapper = FilterMappings.defaults
|
8
8
|
mapper.map(self)
|
9
9
|
end
|
10
10
|
|
11
11
|
def trace_class
|
12
|
-
mapper =
|
12
|
+
mapper = TemplateMappings.defaults
|
13
13
|
mapper.map(self)
|
14
14
|
end
|
15
15
|
|
16
16
|
def appender_class
|
17
|
-
mapper =
|
17
|
+
mapper = AppenderMappings.defaults
|
18
18
|
mapper.map(self)
|
19
19
|
end
|
20
20
|
|
21
21
|
def rule
|
22
|
-
mapper =
|
22
|
+
mapper = RuleMappings.prefix_map
|
23
23
|
mapper.map(self)
|
24
24
|
end
|
25
25
|
|
26
26
|
def appenders
|
27
|
-
self.
|
27
|
+
puts "Appenders from: #{self.inspect}"
|
28
|
+
puts "appender_class: #{self.appender_class.inspect}"
|
29
|
+
self.appender_class.new nil
|
28
30
|
end
|
29
31
|
|
30
32
|
end
|
@@ -7,6 +7,7 @@ module Tracing
|
|
7
7
|
|
8
8
|
# filter on module names and then on class names and methods within those modules
|
9
9
|
def allow_action(msg, context)
|
10
|
+
puts "CM"
|
10
11
|
modules_name = context[:full_modules_name]
|
11
12
|
action = rules[:default] || :yield
|
12
13
|
# puts "modules_name: #{modules_name}"
|
@@ -22,16 +22,18 @@ module Tracing
|
|
22
22
|
# default allow return value
|
23
23
|
allow = (final_yield_action == :exclude ? false : true)
|
24
24
|
|
25
|
-
|
25
|
+
puts "default allow: #{allow}"
|
26
26
|
# puts "filters: #{@filters}"
|
27
27
|
|
28
28
|
return allow if @filters.blank?
|
29
29
|
|
30
|
+
puts "iterate filters"
|
30
31
|
@filters.each do |_filter|
|
32
|
+
puts "filter:" + _filter.inspect
|
31
33
|
# apply filter
|
32
34
|
if _filter
|
33
35
|
res = _filter.allow_action(msg, context)
|
34
|
-
|
36
|
+
puts "res: #{res}"
|
35
37
|
|
36
38
|
if (res == :include_and_yield)
|
37
39
|
allow = true
|
@@ -53,6 +55,8 @@ module Tracing
|
|
53
55
|
break
|
54
56
|
end
|
55
57
|
# puts "yielding..."
|
58
|
+
else
|
59
|
+
puts "filter is null"
|
56
60
|
end
|
57
61
|
end
|
58
62
|
# puts "filters_allow?: #{allow}"
|
data/lib/filters/filter.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
module Tracing
|
2
|
-
|
3
|
-
# interface (abstract class)
|
4
|
-
# instances of this form can be used as filters inside include/exclude lists
|
5
|
-
class NameFilter
|
6
|
-
# return boolean
|
7
|
-
def allow?(name)
|
8
|
-
true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
2
|
# abstract filter
|
14
3
|
class BaseFilter
|
15
4
|
attr_reader :name
|
@@ -17,11 +6,13 @@ module Tracing
|
|
17
6
|
|
18
7
|
class << self
|
19
8
|
attr_accessor :filters
|
20
|
-
|
9
|
+
|
21
10
|
# register symbol => filter mappings
|
22
11
|
def register_filters(hash)
|
23
|
-
|
24
|
-
filters
|
12
|
+
# puts "register_filters: #{hash.inspect}"
|
13
|
+
@filters ||= {}
|
14
|
+
@filters.merge!(hash)
|
15
|
+
return @filters
|
25
16
|
end
|
26
17
|
|
27
18
|
# array of symbols
|
@@ -31,13 +22,17 @@ module Tracing
|
|
31
22
|
filters.reject!{|key, value| hash.include? key}
|
32
23
|
end
|
33
24
|
end
|
34
|
-
|
25
|
+
|
35
26
|
def initialize(options = {})
|
36
27
|
@name = options[:name] || "Unknown filter"
|
37
28
|
end
|
38
29
|
|
39
30
|
def name_allow_action(name)
|
40
|
-
|
31
|
+
puts "name_allow_action: #{name}"
|
32
|
+
# res = rules.rules_allow_action(name)
|
41
33
|
end
|
42
34
|
end
|
43
|
-
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Tracing::BaseFilter.register_filters({})
|
38
|
+
|
@@ -6,7 +6,7 @@ module Tracing::Filter
|
|
6
6
|
# puts "TRY create_filter: " + name_hash.inspect
|
7
7
|
[:module_filter, :class_filter, :method_filter, :vars_filter].each do |symbol|
|
8
8
|
# puts "symbol:" + symbol.to_s
|
9
|
-
res = name_hash.
|
9
|
+
res = name_hash.try_create_filter_hash symbol
|
10
10
|
# puts "Filter created:" + res.inspect
|
11
11
|
return res if res
|
12
12
|
end
|
@@ -6,9 +6,10 @@ module FilterMappings
|
|
6
6
|
:class_rules => :class_filter,
|
7
7
|
:method_rules => :method_filter,
|
8
8
|
:var_rules => :vars_filter,
|
9
|
+
:arg_rules => :args_filter,
|
9
10
|
:modules => :composite_module_filter,
|
10
11
|
:classes => :composite_class_filter,
|
11
|
-
:vars => :
|
12
|
+
:vars => :list_vars_filter
|
12
13
|
}
|
13
14
|
end
|
14
15
|
|
@@ -28,9 +29,10 @@ module FilterMappings
|
|
28
29
|
:class_filter => Tracing::ClassFilter,
|
29
30
|
:method_filter => Tracing::MethodFilter,
|
30
31
|
:vars_filter => Tracing::InstanceVarFilter,
|
32
|
+
:args_filter => Tracing::ArgumentFilter,
|
31
33
|
:composite_module_filter => Tracing::CompositeModuleFilter,
|
32
34
|
:composite_class_filter => Tracing::CompositeClassFilter,
|
33
|
-
:
|
35
|
+
:list_vars_filter => Tracing::ListInstanceVarFilter
|
34
36
|
}
|
35
37
|
end
|
36
38
|
end
|