pangdudu-rofl 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/rofl.rb +12 -11
  2. data/lib/rofl_trace.rb +9 -0
  3. data/lib/test_rofl.rb +1 -1
  4. metadata +1 -1
@@ -1,7 +1,8 @@
1
1
  require 'logger'
2
-
2
+ require 'rofl_trace'
3
3
  #little happy logger module
4
4
  module Rofl
5
+ include RoflTrace
5
6
 
6
7
  attr_accessor :debugname,:logger
7
8
 
@@ -17,39 +18,39 @@ module Rofl
17
18
  @tracing = false
18
19
  #enable tracing
19
20
  if @tracing
20
- require 'rofl_trace'
21
- include RoflTrace
22
- rofl_enable_trace
21
+ rofl_enable_silent_trace
23
22
  end
24
23
  end
25
24
  end
26
25
  #error message
27
26
  def elog text="error"
28
27
  rofl_logger_check #check if logger is setup
29
- @logger.error "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
28
+ @logger.error "#{@debugname}.#{rofl_meth_trace.to_s}: #{text.to_s}"
30
29
  end
31
30
  #warning
32
31
  def wlog text="warning"
33
32
  rofl_logger_check #check if logger is setup
34
- @logger.warning "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
33
+ @logger.warning "#{@debugname}.#{rofl_meth_trace.to_s}: #{text.to_s}"
35
34
  end
36
35
  #info message
37
36
  def ilog text="info"
38
37
  rofl_logger_check #check if logger is setup
39
- @logger.info "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
38
+ @logger.info "#{@debugname}.#{rofl_meth_trace.to_s}: #{text.to_s}"
40
39
  end
41
40
  #debug message
42
41
  def dlog text="debug"
43
42
  rofl_logger_check #check if logger is setup
44
- @logger.debug "#{@debugname}.#{rofl_meth_trace}: #{text.to_s}"
43
+ @logger.debug "#{@debugname}.#{rofl_meth_trace.to_s}: #{text.to_s}"
45
44
  end
46
45
  #get method call trace
47
46
  def rofl_meth_trace
47
+ last_meth_name = "notrace"
48
48
  skip = 2 #indicates how many items we skip in the execution stack trace
49
49
  call_trace = caller(skip)
50
- last_meth = call_trace[0][/\`.*?\'/]
51
- last_meth_name = "notrace"
52
- last_meth_name = last_meth.delete("\`").delete("\'") unless last_meth.nil?
50
+ regexp = /\`.*?\'/
51
+ last_meth = call_trace[0][regexp]
52
+ last_meth_name = last_meth.delete("\`") unless last_meth.nil?
53
+ last_meth_name = last_meth_name.delete("\'") unless last_meth_name.nil?
53
54
  return last_meth_name
54
55
  end
55
56
  #check if we or an object are ready to rofl
@@ -13,6 +13,15 @@ module RoflTrace
13
13
  return
14
14
  end
15
15
 
16
+ #enable vm wide silent tracing
17
+ def rofl_enable_silent_trace event_regex = /^(call)/
18
+ #this is the Kernel::set_trace_func that we overwrite
19
+ trace_func = Proc.new do |event, file, line, id, binding, classname|
20
+ end
21
+ set_trace_func trace_func
22
+ return
23
+ end
24
+
16
25
  #disable vm wide tracing
17
26
  def rofl_disable_trace
18
27
  set_trace_func nil
@@ -16,7 +16,7 @@ class Test
16
16
  other_method
17
17
  end
18
18
  def other_method
19
- puts "puts git other method called"
19
+ ilog "other method called"
20
20
  end
21
21
  end
22
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pangdudu-rofl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pangdudu