Module: Autolog
- Defined in:
- lib/autolog.rb,
lib/autolog/methods.rb,
lib/autolog/version.rb
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- VERSION =
'0.2.0'
Class Attribute Summary collapse
-
.flush ⇒ Object
Returns the value of attribute flush.
-
.procedure ⇒ Object
called procedure instead of proc because set_trace_func proc was calling the proc attribute.
Class Method Summary collapse
-
.c_calls(*args) ⇒ Object
log c-call events only.
-
.c_calls_and_returns(*args) ⇒ Object
log c-call and c-return events only.
-
.c_returns(*args) ⇒ Object
log c-return events only.
-
.class_ends(*args) ⇒ Object
log end events only.
-
.class_starts(*args) ⇒ Object
log class events only.
-
.classes(*args) ⇒ Object
log class and end events only.
-
.events(*args) ⇒ Object
(also: event)
log all specified events.
-
.lines(*args) ⇒ Object
log line events only.
-
.method_calls(*args) ⇒ Object
log call events only.
-
.method_returns(*args) ⇒ Object
log return events only.
-
.methods(*args) ⇒ Object
log call and return events only.
-
.off(*args) ⇒ Object
turn logging off.
-
.raises(*args) ⇒ Object
log raise events only.
- .trace(*args) ⇒ Object
Class Attribute Details
.flush ⇒ Object
Returns the value of attribute flush.
8 9 10 |
# File 'lib/autolog.rb', line 8 def flush @flush end |
.procedure ⇒ Object
called procedure instead of proc because set_trace_func proc was calling the proc attribute. Fun!
7 8 9 |
# File 'lib/autolog.rb', line 7 def procedure @procedure end |
Class Method Details
.c_calls(*args) ⇒ Object
log c-call events only
45 46 47 48 49 50 51 |
# File 'lib/autolog.rb', line 45 def c_calls(*args) if block_given? events ['c-call', args].flatten, &Proc.new else events ['c-call', args].flatten end end |
.c_calls_and_returns(*args) ⇒ Object
log c-call and c-return events only
63 64 65 66 67 68 69 |
# File 'lib/autolog.rb', line 63 def c_calls_and_returns(*args) if block_given? events ['c-call', 'c-return', args].flatten, &Proc.new else events ['c-call', 'c-return', args].flatten end end |
.c_returns(*args) ⇒ Object
log c-return events only
54 55 56 57 58 59 60 |
# File 'lib/autolog.rb', line 54 def c_returns(*args) if block_given? events ['c-return', args].flatten, &Proc.new else events ['c-return', args].flatten end end |
.class_ends(*args) ⇒ Object
log end events only
81 82 83 84 85 86 87 |
# File 'lib/autolog.rb', line 81 def class_ends(*args) if block_given? events ['end', args].flatten, &Proc.new else events ['end', args].flatten end end |
.class_starts(*args) ⇒ Object
log class events only
72 73 74 75 76 77 78 |
# File 'lib/autolog.rb', line 72 def class_starts(*args) if block_given? events ['class', args].flatten, &Proc.new else events ['class', args].flatten end end |
.classes(*args) ⇒ Object
log class and end events only
90 91 92 93 94 95 96 |
# File 'lib/autolog.rb', line 90 def classes(*args) if block_given? events ['class', 'end', args].flatten, &Proc.new else events ['class', 'end', args].flatten end end |
.events(*args) ⇒ Object Also known as: event
log all specified events
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/autolog.rb', line 11 def events(*args) args.flatten! args.collect!{|e|e.to_s.gsub('_','-')} puts "events method received #{args.inspect}" # What's up with the Exception hiding? # Ruby bug 7180: can use up 100% cpu in 1.9.3p194 if let anything be raised. We'll silently rescue and ignore issues. Otherwise, it produces a deluge of output. if args.size == 1 eval "set_trace_func proc {|event, file, line, id, binding, classname| begin; Autolog.procedure.call(event, file, line, id, binding, classname) if event == #{args[0].inspect}; rescue SystemExit, Interrupt; raise; rescue Exception; end}" elsif args.size > 1 eval "set_trace_func proc {|event, file, line, id, binding, classname| begin; Autolog.procedure.call(event, file, line, id, binding, classname) if #{args.inspect}.include?(event); rescue SystemExit, Interrupt; raise; rescue Exception; end}" else set_trace_func proc {|event, file, line, id, binding, classname| begin; Autolog.procedure.call(event, file, line, id, binding, classname); rescue SystemExit, Interrupt; raise; rescue Exception; end} end if block_given? begin yield ensure off end end end |
.lines(*args) ⇒ Object
log line events only
135 136 137 138 139 140 141 |
# File 'lib/autolog.rb', line 135 def lines(*args) if block_given? events ['line', args].flatten, &Proc.new else events ['line', args].flatten end end |
.method_calls(*args) ⇒ Object
log call events only
99 100 101 102 103 104 105 |
# File 'lib/autolog.rb', line 99 def method_calls(*args) if block_given? events ['call', args].flatten, &Proc.new else events ['call', args].flatten end end |
.method_returns(*args) ⇒ Object
log return events only
108 109 110 111 112 113 114 |
# File 'lib/autolog.rb', line 108 def method_returns(*args) if block_given? events ['return', args].flatten, &Proc.new else events ['return', args].flatten end end |
.methods(*args) ⇒ Object
log call and return events only
117 118 119 120 121 122 123 |
# File 'lib/autolog.rb', line 117 def methods(*args) if block_given? events ['call', 'return'], &Proc.new else events ['call', 'return', args].flatten end end |
.off(*args) ⇒ Object
turn logging off
144 145 146 147 |
# File 'lib/autolog.rb', line 144 def off(*args) # accepts *args to make implementation of autolog in methods easier, but ignores them set_trace_func nil end |
.raises(*args) ⇒ Object
log raise events only
126 127 128 129 130 131 132 |
# File 'lib/autolog.rb', line 126 def raises(*args) if block_given? events ['raise', args].flatten, &Proc.new else events ['raise', args].flatten end end |
.trace(*args) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/autolog.rb', line 36 def trace(*args) if block_given? events args, &Proc.new else events args end end |