trace-util-adv 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/TODO.txt +18 -2
  2. data/VERSION +1 -1
  3. data/lib/appenders/appender.rb +1 -1
  4. data/lib/appenders/base_appender.rb +18 -20
  5. data/lib/appenders/include.rb +2 -2
  6. data/lib/appenders/types/html_appender.rb +1 -1
  7. data/lib/appenders/types/logger_appender.rb +1 -1
  8. data/lib/appenders/types/xml_appender.rb +1 -1
  9. data/lib/extensions/hash_extensions.rb +41 -19
  10. data/lib/extensions/hash_rule_extensions.rb +4 -0
  11. data/lib/extensions/symbol_extensions.rb +7 -5
  12. data/lib/filters/composite/composite_class_filter.rb +1 -0
  13. data/lib/filters/composite/composite_module_filter.rb +1 -0
  14. data/lib/filters/executor/filter_exec.rb +6 -2
  15. data/lib/filters/filter.rb +12 -17
  16. data/lib/filters/filter_factory.rb +1 -1
  17. data/lib/filters/filter_mappings.rb +4 -2
  18. data/lib/filters/include.rb +4 -8
  19. data/lib/filters/list/list_instance_var_filter.rb +1 -0
  20. data/lib/filters/name_filter.rb +13 -0
  21. data/lib/filters/simple/argument_filter.rb +2 -1
  22. data/lib/filters/simple/class_filter.rb +1 -1
  23. data/lib/filters/simple/instance_var_filter.rb +9 -6
  24. data/lib/filters/simple/method_filter.rb +1 -0
  25. data/lib/filters/simple/module_filter.rb +6 -3
  26. data/lib/rules/rule_match.rb +5 -4
  27. data/lib/targets/file_target.rb +11 -0
  28. data/lib/templates/base_template.rb +11 -12
  29. data/lib/templates/html_template.rb +35 -36
  30. data/lib/templates/string_template.rb +0 -1
  31. data/lib/templates/template_mappings.rb +4 -4
  32. data/lib/templates/xml_template.rb +0 -1
  33. data/lib/trace-util-adv.rb +36 -20
  34. data/lib/trace_calls/trace_ext.rb +4 -17
  35. data/test/action_handler/include.rb +4 -0
  36. data/test/action_handler/test_action_handler.rb +1 -2
  37. data/test/action_handler/test_create_action_handler.rb +6 -9
  38. data/test/appenders/include.rb +4 -0
  39. data/test/appenders/test_appender_templates.rb +57 -0
  40. data/test/appenders/test_create_appender.rb +9 -10
  41. data/test/extensions/include.rb +4 -0
  42. data/test/extensions/test_filters_creation.rb +4 -28
  43. data/test/extensions/test_hash_extensions.rb +44 -47
  44. data/test/extensions/test_hash_filter_extensions.rb +46 -29
  45. data/test/extensions/test_set_context.rb +9 -11
  46. data/test/extensions/test_string_extensions.rb +1 -3
  47. data/test/extensions/test_symbol_extensions.rb +2 -4
  48. data/test/filters/chain/test_filters_chain.rb +1 -51
  49. data/test/filters/composite/test_composite_class_filter.rb +1 -3
  50. data/test/filters/composite/test_composite_module_filter.rb +1 -3
  51. data/test/filters/composite/test_composite_var_filter.rb +8 -11
  52. data/test/filters/executor/test_filter_exec.rb +1 -3
  53. data/test/filters/include.rb +8 -0
  54. data/test/filters/msg_context/test_custom_filters.rb +13 -14
  55. data/test/filters/simple/test_base_filter.rb +8 -6
  56. data/test/filters/simple/test_class_filter.rb +1 -3
  57. data/test/filters/simple/test_instancevar_filter.rb +5 -9
  58. data/test/filters/simple/test_method_filter.rb +4 -9
  59. data/test/filters/simple/test_module_filter.rb +13 -10
  60. data/test/samples/sample_composite_filters.rb +15 -12
  61. data/test/targets/test_create_targets.rb +21 -0
  62. data/test/templates/include.rb +4 -0
  63. data/test/templates/test_create_templates.rb +23 -0
  64. data/test/templates/test_exec_templates.rb +6 -0
  65. data/test/trace_calls/include.rb +4 -0
  66. data/test/trace_calls/test_configure_.rb +17 -14
  67. data/test/trace_calls/tracing/test_html_tracing.rb +2 -3
  68. data/test/trace_calls/tracing/test_logger_tracing.rb +5 -4
  69. data/test/trace_calls/tracing/test_stream_tracing.rb +2 -3
  70. data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +2 -3
  71. data/test/trace_calls/tracing/test_xml_tracing.rb +2 -3
  72. data/trace-util-adv.gemspec +14 -6
  73. metadata +13 -5
  74. data/test/appenders/test_appender_tracers.rb +0 -56
  75. data/test/tracers/test_create_tracers.rb +0 -46
  76. data/test/tracers/test_exec_tracers.rb +0 -11
data/TODO.txt CHANGED
@@ -1,7 +1,23 @@
1
1
  TODO:
2
2
  ----
3
- - Unit tests for appenders. action_handler
4
- - require txt_file_mutator
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.2.4
1
+ 0.3.0
@@ -8,7 +8,7 @@ module Tracing
8
8
 
9
9
  def register_default_mappings
10
10
  @appender_mappings ||= {}
11
- @appender_mappings.merge!(Mappings.default_appender_mappings)
11
+ @appender_mappings.merge!(AppenderMappings.defaults)
12
12
  end
13
13
 
14
14
  def register_appender_mappings(_appender_mappings)
@@ -4,24 +4,24 @@ module Tracing
4
4
  include Tracing::FilterUse
5
5
 
6
6
  attr_accessor :options
7
- attr_reader :tracer
7
+ attr_reader :templates
8
8
 
9
9
  class << self
10
- attr_accessor :tracers
10
+ attr_accessor :templates
11
11
 
12
12
 
13
- def register_tracers(tracers = nil)
14
- @tracers ||= {} # default_tracers
15
- @tracers = @tracers.merge!(tracers || {})
13
+ def register_templates(templates = nil)
14
+ @templates ||= {} # default_templates
15
+ @templates = @templates.merge!(templates || {})
16
16
  end
17
17
 
18
- def create_tracer(tracer)
19
- tracers ||= register_tracers
20
- if tracer.kind_of?(Symbol) || tracer.kind_of?(String)
21
- tracer_class = tracers[tracer.to_sym] || tracers[:default]
22
- tracer_class.new
23
- elsif tracer.kind_of? Tracing::OutputTemplate::Trace
24
- tracer
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
- tracer = @options[:tracer] if @options
37
- return if !tracer
36
+ template = @options[:template] if @options
37
+ return if !template
38
38
 
39
- tracer = self.class.create_tracer(tracer)
40
- @tracer = tracer
39
+ @template = self.class.create_template(template)
41
40
  elsif init_options.kind_of? Symbol
42
- self.class.register_tracers
43
- tracer = self.class.tracers[init_options]
41
+ self.class.register_templates
42
+ tracer = self.class.templates[init_options]
44
43
  return if !tracer
45
44
 
46
- tracer = self.class.create_tracer(tracer)
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
@@ -1,4 +1,4 @@
1
1
  require 'appenders/base_appender'
2
- include_folder('appenders')
3
- include_folder_rec('appenders/types')
2
+ Require.folder 'appenders'
3
+ Require.folder 'appenders/types'
4
4
 
@@ -3,7 +3,7 @@ module Tracing
3
3
  attr_accessor :to_file, :html_output
4
4
 
5
5
  def initialize(init_options = nil)
6
- @tracer = Tracing::OutputTemplate::HtmlTrace.new
6
+ @tracer = Tracing::HtmlTemplate.new
7
7
  super(init_options)
8
8
  @html_output = html_begin
9
9
 
@@ -36,7 +36,7 @@ module Tracing
36
36
  end
37
37
 
38
38
  def initialize(init_options)
39
- @tracer = Tracing::OutputTemplate::StringTrace.new
39
+ @tracer = Tracing::StringTemplate.new
40
40
  super(init_options)
41
41
 
42
42
  if init_options.kind_of? Hash
@@ -18,7 +18,7 @@ module Tracing
18
18
  end
19
19
 
20
20
  def initialize(init_options = nil)
21
- @tracer = Tracing::OutputTemplate::XmlTrace.new
21
+ @tracer = Tracing::XmlTemplate.new
22
22
  super(init_options)
23
23
  @xml_output = xml_begin
24
24
 
@@ -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
- # return tracer
95
- def tracer
96
- tracer_key = self[:tracer]
97
- tracer_class = Mappings.default_tracer_mappings[tracer_key]
98
- tracer_class.new
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
- # puts "hash: #{hash.inspect} -> class: #{filter_class}"
107
- return filter_class.new(hash) if filter_class
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
- Mappings.convenience_map.select do |key, _filter|
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
- Mappings.filter_rule_mappings.select do |key, _filter|
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
- self[:full_modules_name] = full_modules_name
158
- self[:full_class_name] = full_class_name
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
- self[:full_method_name] = full_method_name
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 = Mappings.default_filters
7
+ mapper = FilterMappings.defaults
8
8
  mapper.map(self)
9
9
  end
10
10
 
11
11
  def trace_class
12
- mapper = Mappings::default_tracer_mappings
12
+ mapper = TemplateMappings.defaults
13
13
  mapper.map(self)
14
14
  end
15
15
 
16
16
  def appender_class
17
- mapper = Mappings::default_appender_mappings
17
+ mapper = AppenderMappings.defaults
18
18
  mapper.map(self)
19
19
  end
20
20
 
21
21
  def rule
22
- mapper = Mappings::rule_symbol_mappings
22
+ mapper = RuleMappings.prefix_map
23
23
  mapper.map(self)
24
24
  end
25
25
 
26
26
  def appenders
27
- self.appender_class.new
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 class names and then methods within those classes
9
9
  def allow_action(msg, context)
10
+ puts "CC"
10
11
  # class name of context
11
12
  class_name = context[:class_name]
12
13
  action = rules[:default] || :yield
@@ -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
- # puts "default allow: #{allow}"
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
- # puts "res: #{res}"
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}"
@@ -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
- @filters ||= {}
24
- filters.merge!(hash)
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
- res = rules.rules_allow_action(name)
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.try_create_filter(symbol)
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 => :composite_vars_filter
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
- :composite_vars_filter => Tracing::CompositeInstanceVarFilter
35
+ :list_vars_filter => Tracing::ListInstanceVarFilter
34
36
  }
35
37
  end
36
38
  end