trace-util-adv 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Advanced TraceUtils tutorial.pdf +0 -0
- data/CHANGELOG +4 -8
- data/{lib/TODO.txt → TODO.txt} +8 -0
- data/VERSION +1 -1
- data/lib/action_handler/action_handler.rb +40 -0
- data/lib/{action_handler.rb → action_handler/action_handler_registration.rb} +3 -41
- data/lib/appenders/appender.rb +1 -13
- data/lib/appenders/appender_mappings.rb +13 -0
- data/lib/appenders/base_appender.rb +2 -11
- data/lib/appenders/file_appender.rb +21 -13
- data/lib/appenders/include.rb +4 -0
- data/lib/appenders/types/README-NOTE.txt +2 -0
- data/lib/appenders/{html_appender.rb → types/html_appender.rb} +4 -20
- data/lib/appenders/{logger_appender.rb → types/logger_appender.rb} +0 -0
- data/lib/appenders/{stream_appender.rb → types/stream_appender.rb} +0 -0
- data/lib/appenders/{template_log_appender.rb → types/template_log_appender.rb} +0 -0
- data/lib/appenders/{xml_appender.rb → types/xml_appender.rb} +1 -1
- data/lib/extensions/array_extensions.rb +42 -0
- data/lib/extensions/hash_extensions.rb +181 -0
- data/lib/extensions/hash_rule_extensions.rb +50 -0
- data/lib/extensions/include.rb +1 -0
- data/lib/extensions/nilclass_extensions.rb +10 -0
- data/lib/extensions/object_extensions.rb +19 -0
- data/lib/extensions/string_extensions.rb +35 -0
- data/lib/extensions/symbol_extensions.rb +30 -0
- data/lib/filters/composite/composite_class_filter.rb +25 -0
- data/lib/filters/composite/composite_module_filter.rb +53 -0
- data/lib/filters/executor/filter_exec.rb +74 -0
- data/lib/filters/filter.rb +43 -0
- data/lib/filters/filter_factory.rb +1 -1
- data/lib/filters/filter_mappings.rb +36 -0
- data/lib/filters/{tracing_filter.rb → filter_registration.rb} +6 -49
- data/lib/filters/filter_use.rb +10 -0
- data/lib/filters/include.rb +8 -0
- data/lib/filters/list/README-NOTE.txt +1 -0
- data/lib/filters/list/list_instance_var_filter.rb +27 -0
- data/lib/filters/{message_filters.rb → msg_context/message_context_filters.rb} +3 -12
- data/lib/filters/simple/argument_filter.rb +24 -0
- data/lib/filters/simple/class_filter.rb +15 -0
- data/lib/filters/simple/instance_var_filter.rb +25 -0
- data/lib/filters/simple/method_filter.rb +17 -0
- data/lib/filters/simple/module_filter.rb +14 -0
- data/lib/{templates/trace_output_handler.rb → output_handler/output_handler.rb} +0 -0
- data/lib/rules/rule_mappings.rb +10 -0
- data/lib/{rule_match.rb → rules/rule_match.rb} +5 -3
- data/lib/targets/README-NOTE.txt +2 -0
- data/lib/targets/file_target.rb +65 -0
- data/lib/targets/stream_target.rb +9 -0
- data/lib/targets/string_target.rb +9 -0
- data/lib/templates/base_template.rb +3 -2
- data/lib/templates/html_template.rb +1 -2
- data/lib/templates/include.rb +2 -0
- data/lib/templates/string_template.rb +24 -25
- data/lib/templates/template_mappings.rb +10 -0
- data/lib/templates/xml_template.rb +28 -29
- data/lib/trace-util-adv.rb +24 -4
- data/lib/{trace_calls.rb → trace_calls/trace_calls.rb} +0 -0
- data/lib/trace_calls/trace_configuration.rb +29 -0
- data/lib/{trace_ext.rb → trace_calls/trace_ext.rb} +10 -9
- data/test/{test_action_handler.rb → action_handler/test_action_handler.rb} +1 -5
- data/test/action_handler/test_create_action_handler.rb +31 -0
- data/test/appenders/test_appender_filters.rb +0 -0
- data/test/appenders/test_appender_tracers.rb +56 -0
- data/test/appenders/test_create_appender.rb +49 -0
- data/test/{test_html_appender.rb → appenders/test_html_appender.rb} +3 -7
- data/test/appenders/test_stream_appender.rb +41 -0
- data/test/appenders/test_template_log_appender.rb +18 -0
- data/test/{test_xml_appender.rb → appenders/test_xml_appender.rb} +0 -0
- data/test/extensions/test_filters_creation.rb +36 -0
- data/test/extensions/test_hash_extensions.rb +208 -0
- data/test/extensions/test_hash_filter_extensions.rb +65 -0
- data/test/extensions/test_set_context.rb +94 -0
- data/test/extensions/test_string_extensions.rb +55 -0
- data/test/extensions/test_symbol_extensions.rb +35 -0
- data/test/{test_filters_chain.rb → filters/chain/test_filters_chain.rb} +2 -1
- data/test/filters/composite/test_composite_class_filter.rb +78 -0
- data/test/filters/composite/test_composite_module_filter.rb +82 -0
- data/test/filters/composite/test_composite_var_filter.rb +103 -0
- data/test/filters/executor/test_filter_exec.rb +80 -0
- data/test/filters/msg_context/test_custom_filters.rb +54 -0
- data/test/filters/simple/test_base_filter.rb +56 -0
- data/test/filters/simple/test_class_filter.rb +75 -0
- data/test/filters/simple/test_instancevar_filter.rb +82 -0
- data/test/filters/simple/test_method_filter.rb +77 -0
- data/test/filters/simple/test_module_filter.rb +63 -0
- data/test/samples/include.rb +1 -0
- data/test/samples/sample_classes.rb +23 -0
- data/test/samples/sample_composite_filters.rb +50 -0
- data/test/samples/sample_filters.rb +58 -0
- data/test/sandbox/matcher.rb +7 -0
- data/test/sandbox/sandbox.rb +25 -0
- data/test/{test_xml_gen.rb → sandbox/test_xml_gen.rb} +0 -0
- data/test/trace_calls/test_configure_.rb +70 -0
- data/test/trace_calls/tracing/test_html_tracing.rb +20 -0
- data/test/trace_calls/tracing/test_logger_tracing.rb +18 -0
- data/test/trace_calls/tracing/test_stream_tracing.rb +17 -0
- data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +18 -0
- data/test/trace_calls/tracing/test_xml_tracing.rb +18 -0
- data/test/tracers/test_create_tracers.rb +46 -0
- data/test/tracers/test_exec_tracers.rb +11 -0
- data/trace-util-adv.gemspec +91 -32
- metadata +91 -32
- data/lib/core_extensions.rb +0 -101
- data/lib/filters/base_filters.rb +0 -178
- data/lib/filters/composite_filters.rb +0 -71
- data/lib/output_templates.rb +0 -5
- data/lib/sample_filters.rb +0 -97
- data/lib/trace_appenders.rb +0 -9
- data/lib/trace_filters.rb +0 -4
- data/test/test_appender.rb +0 -29
- data/test/test_file_appender.rb +0 -32
- data/test/test_filters.rb +0 -112
- data/test/test_filters_create.rb +0 -28
- data/test/test_special_filters.rb +0 -78
@@ -0,0 +1,25 @@
|
|
1
|
+
module Tracing
|
2
|
+
class CompositeClassFilter < BaseFilter
|
3
|
+
def initialize(options)
|
4
|
+
super(options)
|
5
|
+
@rules = options || {}
|
6
|
+
end
|
7
|
+
|
8
|
+
# filter on class names and then methods within those classes
|
9
|
+
def allow_action(msg, context)
|
10
|
+
# class name of context
|
11
|
+
class_name = context[:class_name]
|
12
|
+
action = rules[:default] || :yield
|
13
|
+
rules[:classes].each do |clazz|
|
14
|
+
names=clazz[:names]
|
15
|
+
class_name_match = names.matches_any?(class_name)
|
16
|
+
next if !class_name_match
|
17
|
+
# if name matches rule
|
18
|
+
method_filter = MethodFilter.new(clazz)
|
19
|
+
action = method_filter.allow_action(msg, context)
|
20
|
+
return action if (action == :include || action == :exclude)
|
21
|
+
end
|
22
|
+
return action
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Tracing
|
2
|
+
class CompositeModuleFilter < BaseFilter
|
3
|
+
def initialize(options)
|
4
|
+
super(options)
|
5
|
+
@rules = options || {}
|
6
|
+
end
|
7
|
+
|
8
|
+
# filter on module names and then on class names and methods within those modules
|
9
|
+
def allow_action(msg, context)
|
10
|
+
modules_name = context[:full_modules_name]
|
11
|
+
action = rules[:default] || :yield
|
12
|
+
# puts "modules_name: #{modules_name}"
|
13
|
+
rules[:modules].each do |_module|
|
14
|
+
# get names of modules to match
|
15
|
+
names = _module[:names]
|
16
|
+
class_rules = _module[:class_rules]
|
17
|
+
classes = _module[:classes]
|
18
|
+
method_rules =_module[:method_rules]
|
19
|
+
|
20
|
+
class_name = context[:class_name]
|
21
|
+
method_name = context[:method_name]
|
22
|
+
|
23
|
+
# puts "module names to match: #{names}"
|
24
|
+
# puts "context class_name: #{class_name}"
|
25
|
+
# puts "context method_name: #{method_name}"
|
26
|
+
|
27
|
+
# test if current module name matches any of the module names for this rule
|
28
|
+
next if !names.matches_any?(modules_name)
|
29
|
+
# if name matches rule
|
30
|
+
if classes && !class_name.blank?
|
31
|
+
# puts "CC filter"
|
32
|
+
composite_class_filter = CompositeClassFilter.new(_module)
|
33
|
+
action = composite_class_filter.allow_action(msg, context)
|
34
|
+
return action if (action == :include || action == :exclude)
|
35
|
+
end
|
36
|
+
if class_rules && !class_name.blank?
|
37
|
+
# puts "class filter"
|
38
|
+
class_filter = ClassFilter.new(_module)
|
39
|
+
action = class_filter.allow_action(msg, context)
|
40
|
+
return action if (action == :include || action == :exclude)
|
41
|
+
end
|
42
|
+
if method_rules && !method_name.blank?
|
43
|
+
# puts "method filter"
|
44
|
+
method_filter = MethodFilter.new(_module)
|
45
|
+
action = method_filter.allow_action(msg, context)
|
46
|
+
return action if (action == :include || action == :exclude)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# puts "action: #{action}"
|
50
|
+
return action
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Tracing
|
2
|
+
module Filter
|
3
|
+
# enable execution of filters
|
4
|
+
class Executor
|
5
|
+
attr_accessor :filters, :final_yield_action
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@final_yield_action = options[:final_yield_action] || :exclude
|
9
|
+
@filters ||= []
|
10
|
+
_filters = options.filters
|
11
|
+
# puts "filters exec: #{_filters.inspect}"
|
12
|
+
@filters.add(_filters)
|
13
|
+
end
|
14
|
+
|
15
|
+
# determine if message and context should pass through filter chain
|
16
|
+
# return:
|
17
|
+
# - true to allow
|
18
|
+
# - false to disallow
|
19
|
+
def filters_allow?(msg, context)
|
20
|
+
# puts "method: filters_allow?"
|
21
|
+
|
22
|
+
# default allow return value
|
23
|
+
allow = (final_yield_action == :exclude ? false : true)
|
24
|
+
|
25
|
+
# puts "default allow: #{allow}"
|
26
|
+
# puts "filters: #{@filters}"
|
27
|
+
|
28
|
+
return allow if @filters.blank?
|
29
|
+
|
30
|
+
@filters.each do |_filter|
|
31
|
+
# apply filter
|
32
|
+
if _filter
|
33
|
+
res = _filter.allow_action(msg, context)
|
34
|
+
# puts "res: #{res}"
|
35
|
+
|
36
|
+
if (res == :include_and_yield)
|
37
|
+
allow = true
|
38
|
+
end
|
39
|
+
|
40
|
+
if (res == :exclude_and_yield)
|
41
|
+
allow = false
|
42
|
+
end
|
43
|
+
|
44
|
+
if (res == :include)
|
45
|
+
# puts "included - break"
|
46
|
+
allow = true
|
47
|
+
break
|
48
|
+
end
|
49
|
+
|
50
|
+
if (res == :exclude)
|
51
|
+
# puts "excluded - break"
|
52
|
+
allow = false
|
53
|
+
break
|
54
|
+
end
|
55
|
+
# puts "yielding..."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# puts "filters_allow?: #{allow}"
|
59
|
+
return allow
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
module Tracing
|
67
|
+
module Filter
|
68
|
+
module ExecUse
|
69
|
+
# set to instance of Tracing::Filter:Exec
|
70
|
+
attr_accessor :filter_executor
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,43 @@
|
|
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
|
+
# abstract filter
|
14
|
+
class BaseFilter
|
15
|
+
attr_reader :name
|
16
|
+
attr_accessor :rules
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :filters
|
20
|
+
|
21
|
+
# register symbol => filter mappings
|
22
|
+
def register_filters(hash)
|
23
|
+
@filters ||= {}
|
24
|
+
filters.merge!(hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
# array of symbols
|
28
|
+
# [:special_filter, :stream_filter]
|
29
|
+
def unregister_filters(hash)
|
30
|
+
@filters ||= {}
|
31
|
+
filters.reject!{|key, value| hash.include? key}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(options = {})
|
36
|
+
@name = options[:name] || "Unknown filter"
|
37
|
+
end
|
38
|
+
|
39
|
+
def name_allow_action(name)
|
40
|
+
res = rules.rules_allow_action(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,7 +4,7 @@ module Tracing::Filter
|
|
4
4
|
|
5
5
|
def self.create_filter(name_hash)
|
6
6
|
# puts "TRY create_filter: " + name_hash.inspect
|
7
|
-
[:module_filter, :class_filter, :method_filter].each do |symbol|
|
7
|
+
[:module_filter, :class_filter, :method_filter, :vars_filter].each do |symbol|
|
8
8
|
# puts "symbol:" + symbol.to_s
|
9
9
|
res = name_hash.try_create_filter(symbol)
|
10
10
|
# puts "Filter created:" + res.inspect
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FilterMappings
|
2
|
+
|
3
|
+
def self.rules_map
|
4
|
+
{
|
5
|
+
:module_rules => :module_filter,
|
6
|
+
:class_rules => :class_filter,
|
7
|
+
:method_rules => :method_filter,
|
8
|
+
:var_rules => :vars_filter,
|
9
|
+
:modules => :composite_module_filter,
|
10
|
+
:classes => :composite_class_filter,
|
11
|
+
:vars => :composite_vars_filter
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.convenience_map
|
16
|
+
{
|
17
|
+
:module => :module_filter,
|
18
|
+
:class => :class_filter,
|
19
|
+
:method => :method_filter,
|
20
|
+
:variable => :vars_filter,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def self.defaults
|
26
|
+
{
|
27
|
+
:module_filter => Tracing::ModuleFilter,
|
28
|
+
:class_filter => Tracing::ClassFilter,
|
29
|
+
:method_filter => Tracing::MethodFilter,
|
30
|
+
:vars_filter => Tracing::InstanceVarFilter,
|
31
|
+
:composite_module_filter => Tracing::CompositeModuleFilter,
|
32
|
+
:composite_class_filter => Tracing::CompositeClassFilter,
|
33
|
+
:composite_vars_filter => Tracing::CompositeInstanceVarFilter
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
@@ -24,6 +24,11 @@ module Tracing
|
|
24
24
|
|
25
25
|
def register_filters(reg_filters)
|
26
26
|
@filters ||= []
|
27
|
+
@filters.add(reg_filters.filters)
|
28
|
+
end
|
29
|
+
|
30
|
+
def _register_filters(reg_filters)
|
31
|
+
@filters ||= []
|
27
32
|
|
28
33
|
# puts "Register filters, using: #{reg_filters.inspect}"
|
29
34
|
new_filters = create_filters(reg_filters)
|
@@ -44,53 +49,5 @@ module Tracing
|
|
44
49
|
end
|
45
50
|
|
46
51
|
end
|
47
|
-
|
48
|
-
# enable execution of filters
|
49
|
-
module Exec
|
50
|
-
def filters_allow?(msg, context)
|
51
|
-
# puts "method: filters_allow?"
|
52
|
-
|
53
|
-
@filters ||= Tracing::TraceExt.filters
|
54
|
-
return true if !@filters && !@filters.kind_of?(Array)
|
55
|
-
|
56
|
-
# default allow return value
|
57
|
-
allow = true
|
58
|
-
allow = false if (Tracing::TraceExt.final_yield_action == :exclude)
|
59
|
-
|
60
|
-
@filters.each do |_filter|
|
61
|
-
# apply filter
|
62
|
-
if _filter
|
63
|
-
res = _filter.allow_action(msg, context)
|
64
|
-
# puts "res: #{res}"
|
65
|
-
|
66
|
-
if (res == :include_and_yield)
|
67
|
-
allow = true
|
68
|
-
end
|
69
|
-
|
70
|
-
if (res == :exclude_and_yield)
|
71
|
-
allow = false
|
72
|
-
end
|
73
|
-
|
74
|
-
if (res == :include)
|
75
|
-
# puts "included - break"
|
76
|
-
allow = true
|
77
|
-
break
|
78
|
-
end
|
79
|
-
|
80
|
-
if (res == :exclude)
|
81
|
-
# puts "excluded - break"
|
82
|
-
allow = false
|
83
|
-
break
|
84
|
-
end
|
85
|
-
|
86
|
-
# puts "yielding..."
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
90
|
-
# puts "filters_allow?: #{allow}"
|
91
|
-
return allow
|
92
|
-
end
|
93
|
-
end
|
94
52
|
end
|
95
|
-
end
|
96
|
-
|
53
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# include this on any class that should have filter functionality available
|
2
|
+
# for tracing, this is used on TraceExt, ActionHandler, Appender
|
3
|
+
module Tracing
|
4
|
+
module FilterUse
|
5
|
+
include Tracing::Filter::Registration
|
6
|
+
include Tracing::Filter::ExecUse
|
7
|
+
|
8
|
+
attr_accessor :filters
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Not sure how useful specific list filters (limited to a single kind of filter) are, since you can always just create a list of various kinds of filters.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Tracing
|
2
|
+
class ListInstanceVarFilter < BaseFilter
|
3
|
+
def initialize(options)
|
4
|
+
super(options)
|
5
|
+
@rules = options || {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def allow_action(msg, context)
|
9
|
+
action = rules[:default] || :yield
|
10
|
+
var_rules = rules[:vars]
|
11
|
+
# puts "var rules: #{var_rules.inspect}"
|
12
|
+
# puts "var_rules size: #{var_rules.size}"
|
13
|
+
# puts "context: #{context.inspect}"
|
14
|
+
var_rules.each do |var_rule|
|
15
|
+
# puts "var rule: #{var_rule.inspect}"
|
16
|
+
options = {}
|
17
|
+
options[:var_rules] = var_rule[:var_rules]
|
18
|
+
options[:var_name] = var_rule[:name]
|
19
|
+
|
20
|
+
var_filter = InstanceVarFilter.new(options)
|
21
|
+
action = var_filter.allow_action(msg, context)
|
22
|
+
return action if (action == :include || action == :exclude)
|
23
|
+
end
|
24
|
+
return action
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# interface class
|
4
4
|
module Tracing
|
5
|
-
class
|
5
|
+
class MsgContextFilter
|
6
6
|
def initialize(options)
|
7
7
|
@options = options
|
8
8
|
end
|
@@ -13,7 +13,7 @@ module Tracing
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# example of specific filter on instance variable
|
16
|
-
class
|
16
|
+
class InstanceVarRangeFilter < MsgContextFilter
|
17
17
|
def name_allow_action(msg, context)
|
18
18
|
obj = context[:self]
|
19
19
|
var = obj.instance_variable_get @options[:var]
|
@@ -21,16 +21,7 @@ module Tracing
|
|
21
21
|
return :yield
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
# interface (abstract class)
|
26
|
-
# instances of this form can be used as filters inside include/exclude lists
|
27
|
-
class NameFilter
|
28
|
-
# return boolean
|
29
|
-
def allow?(name)
|
30
|
-
true
|
31
|
-
end
|
32
|
-
end
|
33
24
|
end
|
34
25
|
|
35
26
|
# custom filter
|
36
|
-
my_msg_filter = Tracing::
|
27
|
+
my_msg_filter = Tracing::InstanceVarRangeFilter.new({:range => 0..10, :var => :rating})
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Tracing
|
2
|
+
# filter on instance variables
|
3
|
+
class ArgumentFilter < BaseFilter
|
4
|
+
attr_accessor :var_name
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
super(options)
|
8
|
+
@rules = options[:arg_rules] || {}
|
9
|
+
@var_name = options[:arg_name]
|
10
|
+
end
|
11
|
+
|
12
|
+
def allow_action(msg, context)
|
13
|
+
obj = context[:args]
|
14
|
+
if var_name.kind_of?(Symbol) || var_name.kind_of?(String)
|
15
|
+
key = var_name.to_sym
|
16
|
+
if obj.has_key? key
|
17
|
+
value = obj[key]
|
18
|
+
return name_allow_action(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
:yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tracing
|
2
|
+
# filter on class name
|
3
|
+
class ClassFilter < BaseFilter
|
4
|
+
def initialize(options)
|
5
|
+
super(options)
|
6
|
+
@rules = options[:class_rules] || {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def allow_action(msg, context)
|
10
|
+
name = context[:class_name]
|
11
|
+
# puts "class_name: #{name}"
|
12
|
+
allow = name_allow_action(name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Tracing
|
2
|
+
# filter on instance variables
|
3
|
+
class InstanceVarFilter < BaseFilter
|
4
|
+
attr_accessor :var_name
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
super(options)
|
8
|
+
# puts "create inst.var filter: #{options.inspect}"
|
9
|
+
@rules = options[:var_rules] || {}
|
10
|
+
@var_name = options[:var_name]
|
11
|
+
end
|
12
|
+
|
13
|
+
def allow_action(msg, context)
|
14
|
+
# puts "InstanceVarFilter.allow_action"
|
15
|
+
obj = context[:self]
|
16
|
+
# puts "var_name: #{var_name}"
|
17
|
+
if var_name.kind_of?(Symbol) || var_name.kind_of?(String)
|
18
|
+
value = obj.instance_variable_get("@#{var_name}")
|
19
|
+
# puts "value: #{value}"
|
20
|
+
return name_allow_action(value)
|
21
|
+
end
|
22
|
+
:yield
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tracing
|
2
|
+
# filter on method
|
3
|
+
class MethodFilter < BaseFilter
|
4
|
+
def initialize(options)
|
5
|
+
super(options)
|
6
|
+
# puts "Method filter options: #{options.inspect}"
|
7
|
+
# puts "use :method_rules or :method_filter"
|
8
|
+
@rules = options[:method_rules] || options[:method_filter] || {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def allow_action(msg, context)
|
12
|
+
name = context[:method_name]
|
13
|
+
# puts "allow name?: #{name}"
|
14
|
+
allow = name_allow_action(name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Tracing
|
2
|
+
# filter on module
|
3
|
+
class ModuleFilter < BaseFilter
|
4
|
+
def initialize(options)
|
5
|
+
super(options)
|
6
|
+
@rules = options[:module_rules] || {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def allow_action(msg, context)
|
10
|
+
name = context[:full_modules_name]
|
11
|
+
allow = name_allow_action(name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -3,13 +3,15 @@ module Tracing
|
|
3
3
|
class RuleTypeError < RuntimeError; end
|
4
4
|
|
5
5
|
def matches_any?(name)
|
6
|
-
|
6
|
+
puts "matches any: #{name.inspect}"
|
7
7
|
self.any? do |rule|
|
8
|
+
puts "rule:" + rule.inspect
|
9
|
+
puts "against:" + name.inspect
|
8
10
|
if rule.kind_of? Regexp
|
9
11
|
# match return position of match, or nil if no match
|
10
12
|
# here converted into boolean result
|
11
|
-
match = (name =~ rule)
|
12
|
-
|
13
|
+
match = !(name =~ rule).nil?
|
14
|
+
puts "match: #{match}"
|
13
15
|
match
|
14
16
|
elsif rule.kind_of? String
|
15
17
|
match = (name == rule)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Tracing
|
2
|
+
class FileTarget
|
3
|
+
include Tracing::DefaultPath
|
4
|
+
class << self
|
5
|
+
include Tracing::DefaultPath
|
6
|
+
end
|
7
|
+
|
8
|
+
def append(txt, context)
|
9
|
+
file = get_file(context)
|
10
|
+
write_file(file, txt)
|
11
|
+
end
|
12
|
+
|
13
|
+
# file
|
14
|
+
def write_file(file, txt)
|
15
|
+
file = file_path(file)
|
16
|
+
|
17
|
+
write_mode = mode(file)
|
18
|
+
File.open(file, write_mode) do |f|
|
19
|
+
f.puts txt
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_initial_file(file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def insert_into_file(file, txt, marker_txt)
|
27
|
+
line = marker_txt
|
28
|
+
|
29
|
+
file = file_path(file)
|
30
|
+
|
31
|
+
if !File.exist?(file)
|
32
|
+
create_initial_file(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
gsub_file file, /(#{Regexp.escape(line)})/mi do |match|
|
36
|
+
"#{txt}\n#{match}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# helper for deciding file "write mode"
|
41
|
+
def is_old_file?(file)
|
42
|
+
File.new(file).mtime < (Time.now - time_limit)
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_path(file)
|
46
|
+
def_path = default_path || self.class.default_path
|
47
|
+
file = File.join(def_path, file) if self.class.default_path
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def gsub_file(path, regexp, *args, &block)
|
52
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
53
|
+
File.open(path, 'wb') { |file| file.write(content) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# default file "write mode"
|
57
|
+
def mode(file)
|
58
|
+
if !options[:overwrite] && File.exist?(file) && !is_old_file?(file)
|
59
|
+
"a+"
|
60
|
+
else
|
61
|
+
"w+"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|