In Java, with AOP magic and bytecode manipulation under the covers,
you could do something like this: (psuedocode, in real java it would
be xml or annotations)
For methods that are: public, name matches foo*, members of classes
Bar and Boo, intercept and log by calling myLogger
then myLogger would get the method object, and be able to log the
name, time of call, parameters, etc...
I know in Ruby you can very easily turn methods or blocks into
objects, and even do some things similiar to basic AOP, but can
something like this be done?
Module AOPLogger
log_methods :criteria => "all", :log => :method_name, :time, :date
Where log_methods is a class method to be implemented in AOPLogger and
then extend'ed into classes where you want method calls intercepted
and logged.
I imagine something like this might be possible by establishing a
proxy object around objects you want mixed in, then tying into
method_missing, though I imagine it would get nasty quick.
Any ideas?
- Rob
ps - a related, but simpler question - is there a way inside a method
body to get the name of that method reflectively?
ie: def foo
logger.debug("method called is #{method_name})
end
=> "method called is foo"