4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/method_call_logger.rb', line 4
def method_call_logging(option={})
Class.add_proc(
proc {|event, file, line, id, binding, klass|
if event == "call" && klass == self
if id != :initialize
msg = "#{self.to_s}##{id.to_s}"
unless binding.local_variables.empty?
msg += "("
msg += binding.local_variables.map{|vname|
"#{vname}:#{binding.local_variable_get(vname).inspect}"
}.join(", ")
msg += ")"
end
logger = binding.receiver.instance_variable_get(:@logger)
if option[id]
logger.log(option[id], msg)
else
logger.debug(msg)
end
end
end
}
)
end
|