Better way to log method calls in Python?

前端 未结 5 1041
醉梦人生
醉梦人生 2020-12-14 08:35

We can code out some sort of logging decorator to echo function/method calls like the following:

def log(fn):
    ...

@log
def foo():
    ...

class Foo(obj         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 09:09

    Well, If you do not want to explicitly decorate all your functions, you can get all the functions/methods of a given module and apply your decorator automatically. not the easiest thing but not infeasible in python :)

    You can also try an aspect oriented programming framework.

    my2c

提交回复
热议问题