Created
August 21, 2010 05:40
-
-
Save ihower/541832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# idea from http://www.codemud.net/~thinker/GinGin_CGI.py/show_id_doc/201 | |
def log(logfile): | |
def assign_call(call): | |
return lambda *args, **kws: logfile.write(call.__name__) and call(*args, **kws) | |
return assign_call | |
class Foo(object): | |
@log(file('my.log',"w")) | |
def bar(): | |
pass | |
f = Foo() | |
f.bar() | |
f.bar() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Class | |
def log(name, logfile) | |
original_c_m = instance_method(name) | |
define_method name do |*args| | |
logfile.write caller | |
original_c_m.bind(self).call(*args) | |
end | |
end | |
end | |
class Foo | |
def foo | |
end | |
log :foo, File.new("my.log", "w") | |
end | |
f = Foo.new | |
f.foo | |
f.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment