Autolog: shortcut for set_trace_func to debug ruby via console output, etc

If it helps anyone, I wrote a shortcut for set_trace_func, so next time
you want to just add a line before and after some function you are
trying to debug you can have Ruby temporarily output every line, method,
etc. executed. Also, it lets you define the format, use other loggers,
etc. via a proc/lambda define, since you might not like the default
format. Apologize for posting here if it wouldn’t help- maybe you are
using a real debugger.

Example:

In Gemfile add:
gem ‘autolog’

Around some part of code add this before:
Autolog.methods
and this after:
Autolog.off

Hope it helps someone who needs a quick tool periodically without all
the time sink of profiling or setting a breakpoint and debugging in a
slow IDE.

On Wed, Oct 17, 2012 at 8:35 PM, Gary W. [email protected]
wrote:

Around some part of code add this before:
Autolog.methods
and this after:
Autolog.off

I’d prefer using a block for robustness.

autolog do

end

Kind regards

robert

On Oct 17, 2012, at 11:35 , Gary W. [email protected] wrote:

In Gemfile add:

GitHub - garysweaver/autolog: Automatically log events like executed lines, methods, class and module definitions, C-language routines, and/or raises in Ruby.

How does this compare to stdlib’s tracer?

Start tracing

=== Example

Tracer.on

# code to trace here

Tracer.off

You can also pass a block:

Tracer.on {

# trace everything in this block

}

Robert K. wrote in post #1080211:

On Wed, Oct 17, 2012 at 8:35 PM, Gary W. [email protected]
wrote:

Around some part of code add this before:
Autolog.methods
and this after:
Autolog.off

I’d prefer using a block for robustness.

autolog do

end

Kind regards

robert

Done. Added in v0.1.0 and available now in rubygems.org. Added method to
main object and Object. Sound ok? Old syntax still works, too.

Anyone interested in this may also be interested in TracePoint
https://github.com/rubyworks/tracepoint

Ryan D. wrote in post #1080212:

On Oct 17, 2012, at 11:35 , Gary W. [email protected] wrote:

In Gemfile add:

GitHub - garysweaver/autolog: Automatically log events like executed lines, methods, class and module definitions, C-language routines, and/or raises in Ruby.

How does this compare to stdlib’s tracer?

Start tracing

=== Example

Tracer.on

# code to trace here

Tracer.off

You can also pass a block:

Tracer.on {

# trace everything in this block

}

It is basically like an event-specific version of Tracer.

autolog :methods
autolog :c_calls
autolog :c_returns
autolog :c_calls_and_returns
autolog :class_starts
autolog :class_ends
autolog :classes
autolog :method_calls
autolog :method_returns
autolog :methods
autolog :lines
autolog :raises
autolog :trace
autolog :event :c_return
autolog :events ‘raise’, ‘c-call’
autolog :events :raise, :c_call
autolog :off

Autolog.c_calls
Autolog.c_returns
Autolog.c_calls_and_returns
Autolog.class_starts
Autolog.class_ends
Autolog.classes
Autolog.method_calls
Autolog.method_returns
Autolog.methods
Autolog.lines
Autolog.raises
Autolog.trace
Autolog.event :c_return
Autolog.events ‘raise’, ‘c-call’
Autolog.events :raise, :c_call
Autolog.off

Now takes blocks:

autolog do
puts “this is something”
puts “this is something 2”
end

autolog :methods do

end

autolog :c_calls_and_returns do

end

autolog :lines do

end

autolog :events, :line, :c_call do

end

Can use in main, Object, or call methods on it.

Could use some help making it better if anyone wants to help.

Jonathan T. wrote in post #1080250:

Anyone interested in this may also be interested in TracePoint
https://github.com/rubyworks/tracepoint

Thanks! I’ll add that link to the autolog readme as an alternative.